Package java.nio.channels

Examples of java.nio.channels.FileChannel.tryLock()


    @Override
    protected ByteBuffer getXMPBytes(File jpeg) throws IOException, XMPReadException{
        ByteBuffer result = null;
        FileChannel input = (new FileInputStream(jpeg)).getChannel();
        FileLock lock = input.tryLock(0L, Long.MAX_VALUE, true);
        if(lock == null){
            input.close();
            throw new IOException("Cannot lock input file.");
        }
        try{
View Full Code Here


                /*
                 * if lock is unsupported and IOException thrown, just let the
                 * IOException throws out and exit otherwise it will go into an
                 * undead cycle
                 */
                lock = channel.tryLock();
                if (null == lock) {
                    try{
                        fileStream.close();
                    }catch(Exception e){
                        //ignore
View Full Code Here

        String f = getBaseDir() + "/fs/test.data";
        FileUtils.createDirectories(getBaseDir() + "/fs");
        FileChannel c = FileUtils.open(f, "rw");
        c.position(4000);
        c.write(ByteBuffer.wrap(new byte[1]));
        FileLock lock = c.tryLock();
        c.truncate(0);
        if (lock != null) {
            lock.release();
        }
        c.close();
View Full Code Here

        String path = fsBase + "/test";
        assertEquals("test", FileUtils.getName(path));
        can = FilePath.get(fsBase).toRealPath().toString();
        String can2 = FileUtils.toRealPath(FileUtils.getParent(path));
        assertEquals(can, can2);
        FileLock lock = channel.tryLock();
        if (lock != null) {
            lock.release();
        }
        assertEquals(10000, channel.size());
        channel.close();
View Full Code Here

            boolean writable;

            try {
                fos = new FileOutputStream(file, true);
                FileChannel channel = fos.getChannel();
                lock = channel.tryLock();
            } catch (IOException e) {
                log.warn("Error while attempting to lock the file: " + file.getName(), e);
                writable = false;
            } finally {
                if (lock != null) {
View Full Code Here

        {
            channel = new RandomAccessFile(sourceFile, "rw").getChannel();

            // Try acquiring the lock without blocking. This method returns
            // null or throws an exception if the file is already locked.
            lock = channel.tryLock();
        }
        catch (FileNotFoundException fnfe)
        {
            throw new DefaultMuleException(FileMessages.fileDoesNotExist(sourceFile.getName()));
        }
View Full Code Here

        FileLock lock = null;
        ByteBuffer bb = null;
        try {
            channel = fos.getChannel();
            if (channel != null) {
                lock = channel.tryLock();
            }
            bb = getTempByteBuffer();
        } catch (Throwable t) {
        }
        if (lock == null || bb == null || !bb.hasArray()) {
View Full Code Here

        FileLock lock = null;
        ByteBuffer bb = null;
        try {
            channel = fos.getChannel();
            if (channel != null) {
                lock = channel.tryLock();
            }
            bb = getTempByteBuffer();
        } catch (Throwable t) {
        }
        if (lock == null || bb == null || !bb.hasArray()) {
View Full Code Here

                }

                // get the lock using either try lock or not depending on if we are using timeout or not
                FileLock lock = null;
                try {
                    lock = timeout > 0 ? channel.tryLock() : channel.lock();
                } catch (IllegalStateException ex) {
                    // Also catch the OverlappingFileLockException here. Do nothing here                   
                }
                if (lock != null) {
                    if (LOG.isTraceEnabled()) {
View Full Code Here

                        case LOCK_EX | LOCK_NB:
                            if (currentLock != null) {
                                currentLock.release();
                                currentLock = null;
                            }
                            currentLock = fileChannel.tryLock();
                            if (currentLock != null) {
                                return RubyFixnum.zero(context.getRuntime());
                            }

                            break;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.