Package java.nio.channels

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


    Lock writeLock = writeLock(row);
    File file = getFile(row, true);
    try {
      FileInputStream fis = new FileInputStream(file);
      FileChannel channel = fis.getChannel();
      FileLock fileLock = channel.lock();
      try {
        Row<T, K> tStringRow = _get(row);
        if (tStringRow == null) return null;
        T mutate = tMutator.mutate(tStringRow.value);
        if (mutate != null) {
View Full Code Here


    } catch (FileNotFoundException e) {
      try {
        if (file.createNewFile()) {
          FileInputStream fis = new FileInputStream(file);
          FileChannel channel = fis.getChannel();
          FileLock fileLock = channel.lock();
          try {
            if (file.length() == 0) {
              T created = tCreator.create();
              put(row, created);
              return new Row<T, K>(created, row);
View Full Code Here

    // Clear any current interrupt (see LOGBACK-875)
    boolean interrupted = Thread.interrupted();

    FileLock fileLock = null;
    try {
      fileLock = fileChannel.lock();
      long position = fileChannel.position();
      long size = fileChannel.size();
      if (size != position) {
        fileChannel.position(size);
      }
View Full Code Here

        f.createNewFile();
        RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
        FileChannel fcr = raf.getChannel();

        try {
            fcr.lock(0L, Long.MAX_VALUE, false);
            fail("NonWritableChannelException expected!");
        } catch (NonWritableChannelException e) {}
        raf.close();
    }
View Full Code Here

        out.close();

        fc = new RandomAccessFile(f, "rw").getChannel();
        anotherfc = new RandomAccessFile(f, "rw").getChannel();

        assertNotNull(fc.lock());

        ByteBuffer readBuf = ByteBuffer.allocate(100);
        ByteBuffer writeBuf = ByteBuffer.wrap("bytes".getBytes());
        try {
            try {
View Full Code Here

    public void test_release() throws Exception {
        File file = File.createTempFile("test", "tmp");
        file.deleteOnExit();
        FileOutputStream fout = new FileOutputStream(file);
        FileChannel fileChannel = fout.getChannel();
        FileLock fileLock = fileChannel.lock();
        fileChannel.close();
        try {
            fileLock.release();
            fail("should throw ClosedChannelException");
        } catch (ClosedChannelException e) {
View Full Code Here

        }

        // release after release
        fout = new FileOutputStream(file);
        fileChannel = fout.getChannel();
        fileLock = fileChannel.lock();
        fileLock.release();
        fileChannel.close();
        try {
            fileLock.release();
            fail("should throw ClosedChannelException");
View Full Code Here

            try
            {
                Properties props = new Properties();

                channel = new RandomAccessFile( touchfile, "rw" ).getChannel();
                lock = channel.lock( 0, channel.size(), false );

                if ( touchfile.canRead() )
                {
                    getLogger().debug( "Reading resolution-state from: " + touchfile );
                    ByteBuffer buffer = ByteBuffer.allocate( (int) channel.size() );
View Full Code Here

            {
                Properties props = new Properties();

                stream = new FileInputStream( touchfile );
                channel = stream.getChannel();
                lock = channel.lock( 0, channel.size(), true );

                getLogger().debug( "Reading resolution-state from: " + touchfile );
                props.load( stream );

                return props;
View Full Code Here

            try
            {
                Properties props = new Properties();

                channel = new RandomAccessFile( touchfile, "rw" ).getChannel();
                lock = channel.lock( 0, channel.size(), false );

                if ( touchfile.canRead() )
                {
                    getLogger().debug( "Reading resolution-state from: " + touchfile );
                    ByteBuffer buffer = ByteBuffer.allocate( (int) channel.size() );
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.