@Override public void readAll( ByteBuffer dst ) throws IOException { inner.readAll( dst ); }
@Override public void readAll( ByteBuffer dst ) throws IOException { delegate.readAll( dst ); }
@Override public void readAll( ByteBuffer dst ) throws IOException { delegate.readAll( dst ); }
private static void readHeader( StoreChannel channel, ByteBuffer buffer ) throws IOException { try { channel.readAll( buffer ); } catch ( IllegalStateException e ) { ByteBuffer exceptionBuffer = buffer.duplicate(); exceptionBuffer.flip(); throw new InvalidIdGeneratorException( "Unable to read header, bytes read: " + Arrays.toString( getBufferBytes( exceptionBuffer ) ) ); } }
private static ByteBuffer readLong( StoreChannel readChannel ) throws IOException { ByteBuffer readBuffer = allocate( 8 ); readChannel.readAll( readBuffer ); readBuffer.flip(); return readBuffer; }
private void readIdBatch0() throws IOException { if ( stackPosition == 0 ) { return; } long startPosition = max( stackPosition - batchSize * ID_ENTRY_SIZE, 0 ); int bytesToRead = toIntExact( stackPosition - startPosition ); ByteBuffer readBuffer = ByteBuffer.allocate( bytesToRead ); channel.position( startPosition ); channel.readAll( readBuffer ); stackPosition = startPosition; readBuffer.flip(); int idsRead = bytesToRead / ID_ENTRY_SIZE; for ( int i = 0; i < idsRead; i++ ) { long id = readBuffer.getLong(); readFromDisk.enqueue( id ); } if ( aggressiveMode ) { truncate( startPosition ); } }
private String readFailure( File failureFile ) throws IOException { try ( StoreChannel channel = fs.open( failureFile, OpenMode.READ ) ) { byte[] data = new byte[(int) channel.size()]; channel.readAll( ByteBuffer.wrap( data ) ); return UTF8.decode( withoutZeros( data ) ); } }
private boolean isFailed( File failureFile ) throws IOException { try ( StoreChannel channel = fs.open( failureFile, OpenMode.READ ) ) { byte[] data = new byte[(int) channel.size()]; channel.readAll( ByteBuffer.wrap( data ) ); channel.close(); return !allZero( data ); } }
private ByteBuffer readIntoBuffer( String fileName ) throws IOException { ByteBuffer buffer = ByteBuffer.allocate( 16 ); try ( StoreChannel channel = fs.open( file( fileName ), OpenMode.READ ) ) { channel.readAll( buffer ); } buffer.flip(); return buffer; }
private static void verifyFileIsFullOfLongIntegerOnes( StoreChannel channel ) { try { long claimedSize = channel.size(); ByteBuffer buffer = allocate( (int) claimedSize ); channel.readAll( buffer ); buffer.flip(); for ( int position = 0; position < claimedSize; position += 8 ) { long value = buffer.getLong( position ); assertEquals( 1, value ); } } catch ( IOException e ) { throw new RuntimeException( e ); } }
private ByteBuffer readFile( File file ) throws IOException { try ( StoreChannel channel = fileSystemRule.get().open( file, OpenMode.READ ) ) { ByteBuffer buffer = ByteBuffer.allocate( (int) channel.size() ); channel.readAll( buffer ); buffer.flip(); return buffer; } }
/** * Store failure in failure file for index with the given id * * @param failure message describing the failure that needs to be stored * @throws IOException if the failure could not be stored */ public synchronized void storeIndexFailure( String failure ) throws IOException { File failureFile = failureFile(); try ( StoreChannel channel = fs.open( failureFile, OpenMode.READ_WRITE ) ) { byte[] existingData = new byte[(int) channel.size()]; channel.readAll( ByteBuffer.wrap( existingData ) ); channel.position( lengthOf( existingData ) ); byte[] data = UTF8.encode( failure ); channel.writeAll( ByteBuffer.wrap( data, 0, Math.min( data.length, MAX_FAILURE_SIZE ) ) ); channel.force( true ); channel.close(); } }
@Test void absoluteVersusRelative() throws Exception { // GIVEN File file = new File( "myfile" ); StoreChannel channel = fileSystem.open( file, OpenMode.READ_WRITE ); byte[] bytes = "test".getBytes(); channel.write( ByteBuffer.wrap( bytes ) ); channel.close(); // WHEN channel = fileSystem.open( new File( file.getAbsolutePath() ), OpenMode.READ ); byte[] readBytes = new byte[bytes.length]; channel.readAll( ByteBuffer.wrap( readBytes ) ); // THEN assertTrue( Arrays.equals( bytes, readBytes ) ); }
try ( StoreChannel channel = fs.open( file( "a" ), OpenMode.READ ) ) channel.readAll( buf );
@Test public void createShouldClearExistingFile() throws Exception { // given byte[] someBytes = fileWithContent(); // when populator.create(); // then try ( StoreChannel r = fs.open( getIndexFile(), OpenMode.READ ) ) { byte[] firstBytes = new byte[someBytes.length]; r.readAll( ByteBuffer.wrap( firstBytes ) ); assertNotEquals( "Expected previous file content to have been cleared but was still there", someBytes, firstBytes ); } populator.close( true ); }
fileChannel.readAll( buffer ); buffer.flip(); assertEquals( (byte) 0, buffer.get() );
channel.readAll( bufA ); bufA.flip(); bufB.clear();
@Override public void readAll( ByteBuffer dst ) throws IOException { delegate.readAll( dst ); }
@Override public void readAll( ByteBuffer dst ) throws IOException { inner.readAll( dst ); }
private static void readHeader( StoreChannel channel, ByteBuffer buffer ) throws IOException { try { channel.readAll( buffer ); } catch ( IllegalStateException e ) { ByteBuffer exceptionBuffer = buffer.duplicate(); exceptionBuffer.flip(); throw new InvalidIdGeneratorException( "Unable to read header, bytes read: " + Arrays.toString( getBufferBytes( exceptionBuffer ) ) ); } }