/*
 * This file is part of libbluray
 * Copyright (C) 2014  Petri Hintukainen <phintuka@users.sourceforge.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
 */

package org.videolan;

import java.io.IOException;
import java.io.RandomAccessFile;

class LockFile {

    private LockFile(RandomAccessFile lockFile) {
        this.lockFile = lockFile;
    }

    public static LockFile create(String path) {

        try {
            RandomAccessFile os = new RandomAccessFile(path, "rw");
            if (os.getChannel().tryLock() != null) {
                try {
                    /* Test if locking works: second tryLock() should fail */
                    if (os.getChannel().tryLock() != null) {
                        try {
                            os.close();
                        } catch (Exception e) {
                        }
                        logger.error("File locking is unreliable !");
                        return null;
                    }
                } catch (Exception e) {
                }
                return new LockFile(os);
            } else {
                logger.info("Failed locking " + path);
            }
        } catch (Exception e) {
            logger.error("Failed creating lock file: " + e);
        }
        return null;
    }

    public void release() {
        try {
            if (lockFile != null) {
                lockFile.close();
            }
        } catch (Exception e) {
        }
    }

    private RandomAccessFile lockFile;

    private static final Logger logger = Logger.getLogger(LockFile.class.getName());
}

@@ -1166,34 +1166,8 @@
 ) %7B%0A
-                try %7B%0A    
     
@@ -1244,36 +1244,32 @@
                 
-   
- 
 if (os.getChanne
@@ -1309,28 +1309,24 @@
             
-    
 try %7B%0A      
@@ -1343,20 +1343,16 @@
         
-   
- 
 os.close
@@ -1347,36 +1347,32 @@
     os.close();%0A
-    
                 
@@ -1415,34 +1415,26 @@
             
-  
-  %7D%0A    
+%7D%0A
             
@@ -1499,36 +1499,32 @@
                 
-    
 return null;%0A   
@@ -1524,70 +1524,8 @@
 ll;%0A
-                    %7D%0A                %7D catch (Exception e) %7B%0A
     

Remove useless try {} catch {}