Package java.nio.channels

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


            long position = generator.nextInt((int)testSize);
            c.position(position);

            long newSize = generator.nextInt((int)testSize);
            c.truncate(newSize);

            if (c.size() != newSize)
                throw new RuntimeException("Truncate failed");

            if (position > newSize) {
View Full Code Here


            FileUtil.createNewFile(target);
        } else if (endpoint.getFileExist() == GenericFileExist.Override) {
            LOG.debug("Truncating existing file: {}", target);
            FileChannel out = new FileOutputStream(target).getChannel();
            try {
                out.truncate(0);
            } finally {
                IOHelper.close(out, target.getName(), LOG, endpoint.isForceWrites());
            }
        }
    }
View Full Code Here

        File mf = b.getMetaFile();
        // Truncate a block file that has a corresponding metadata file
        if (f.exists() && f.length() != 0 && mf.exists()) {
          FileOutputStream s = new FileOutputStream(f);
          FileChannel channel = s.getChannel();
          channel.truncate(0);
          LOG.info("Truncated block file " + f.getAbsolutePath());
          return b.getBlockId();
        }
      }
    }
View Full Code Here

            FileUtil.createNewFile(target);
        } else if (endpoint.getFileExist() == GenericFileExist.Override) {
            LOG.debug("Truncating existing file: {}", target);
            FileChannel out = new FileOutputStream(target).getChannel();
            try {
                out.truncate(0);
            } finally {
                IOHelper.close(out, target.getName(), LOG, endpoint.isForceWrites());
            }
        }
    }
View Full Code Here

                final long length = getCurrentJournalSize();
                final boolean matches = length == (_writeBuffer.position() + _writeBufferAddress) % _blockSize;
                final FileChannel channel = getFileChannel(_currentAddress);
                Debug.$assert1.t(matches);
                if (matches) {
                    channel.truncate(length);
                }
                channel.force(true);
            } catch (final IOException ioe) {
                throw new PersistitIOException(ioe);
            }
View Full Code Here

            target.createNewFile();
        } else if (endpoint.getFileExist() == GenericFileExist.Override) {
            LOG.debug("Truncating existing file: {}", target);
            FileChannel out = new FileOutputStream(target).getChannel();
            try {
                out.truncate(0);
            } finally {
                IOHelper.force(out, target.getName(), LOG);
                IOHelper.close(out, target.getName(), LOG);
            }
        }
View Full Code Here

                    highId = i;
                }
                // nextId();
            }
            highId++;
            fileChannel.truncate( highId * recordSize );
        }
        catch ( IOException e )
        {
            throw new UnderlyingStorageException(
                "Unable to rebuild id generator " + getStorageFileName(), e );
View Full Code Here

        try
        {
            log.setLevel( Level.OFF );
            createEmptyStore( dynamicStoreFile(), 30 );
            FileChannel fileChannel = new RandomAccessFile( dynamicStoreFile(), "rw" ).getChannel();
            fileChannel.truncate( fileChannel.size() - 2 );
            fileChannel.close();
            DynamicArrayStore store = newStore();
            store.makeStoreOk();
            store.close();
        }
View Full Code Here

        buffer.clear();
        FileChannel fileChannel = new RandomAccessFile( file( "nioneo_logical.log." +
            active ), "rw" ).getChannel();
        if ( fileChannel.size() > size )
        {
            fileChannel.truncate( size );
        }
        else
        {
            fileChannel.position( size );
            ByteBuffer buf = ByteBuffer.allocate( 1 );
View Full Code Here

    {
        // change active log
        FileChannel fc = new RandomAccessFile( logSwitcherFileName, "rw" )
            .getChannel();
        ByteBuffer buf = ByteBuffer.wrap( UTF8.encode( newFileName ) );
        fc.truncate( 0 );
        fc.write( buf );
        fc.force( true );
        fc.close();
    }
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.