/** * read <i>length</i> bytes from <i>position</i> of a file channel */ public static byte[] readFromFileChannel(FileChannel channel, long position, int length) throws IOException { byte[] res = new byte[length]; readFromFileChannelWithEofException(channel, position, res, 0, length); return res; }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "]"); } if (position < getFirstOperationOffset()) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + getFirstOperationOffset() + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
@Override protected void readBytes(ByteBuffer targetBuffer, long position) throws IOException { try { if (position + targetBuffer.remaining() > getWrittenOffset()) { synchronized (this) { // we only flush here if it's really really needed - try to minimize the impact of the read operation // in some cases ie. a tragic event we might still be able to read the relevant value // which is not really important in production but some test can make most strict assumptions // if we don't fail in this call unless absolutely necessary. if (position + targetBuffer.remaining() > getWrittenOffset()) { outputStream.flush(); } } } } catch (final Exception ex) { closeWithTragicEvent(ex); throw ex; } // we don't have to have a lock here because we only write ahead to the file, so all writes has been complete // for the requested location. Channels.readFromFileChannelWithEofException(channel, position, targetBuffer); }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "], generation: [" + getGeneration() + "], path: [" + path + "]"); } if (position < getFirstOperationOffset()) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + getFirstOperationOffset() + "], generation: [" + getGeneration() + "], path: [" + path + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
/** * read <i>length</i> bytes from <i>position</i> of a file channel */ public static byte[] readFromFileChannel(FileChannel channel, long position, int length) throws IOException { byte[] res = new byte[length]; readFromFileChannelWithEofException(channel, position, res, 0, length); return res; }
/** * read <i>length</i> bytes from <i>position</i> of a file channel */ public static byte[] readFromFileChannel(FileChannel channel, long position, int length) throws IOException { byte[] res = new byte[length]; readFromFileChannelWithEofException(channel, position, res, 0, length); return res; }
/** * read <i>length</i> bytes from <i>position</i> of a file channel */ public static byte[] readFromFileChannel(FileChannel channel, long position, int length) throws IOException { byte[] res = new byte[length]; readFromFileChannelWithEofException(channel, position, res, 0, length); return res; }
/** * read <i>length</i> bytes from <i>position</i> of a file channel */ public static byte[] readFromFileChannel(FileChannel channel, long position, int length) throws IOException { byte[] res = new byte[length]; readFromFileChannelWithEofException(channel, position, res, 0, length); return res; }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "]"); } if (position < firstOperationOffset) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + firstOperationOffset + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "]"); } if (position < firstOperationOffset) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + firstOperationOffset + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
@Override protected void readBytes(ByteBuffer buffer, long position) throws IOException { try (ReleasableLock lock = readLock.acquire()) { Channels.readFromFileChannelWithEofException(channel, position, buffer); } }
@Override protected void readBytes(ByteBuffer targetBuffer, long position) throws IOException { try (ReleasableLock lock = readLock.acquire()) { if (position >= writtenOffset) { assert targetBuffer.hasArray() : "buffer must have array"; final int sourcePosition = (int) (position - writtenOffset); System.arraycopy(buffer, sourcePosition, targetBuffer.array(), targetBuffer.position(), targetBuffer.limit()); targetBuffer.position(targetBuffer.limit()); return; } } // we don't have to have a read lock here because we only write ahead to the file, so all writes has been complete // for the requested location. Channels.readFromFileChannelWithEofException(channel, position, targetBuffer); }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "]"); } if (position < getFirstOperationOffset()) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + getFirstOperationOffset() + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "]"); } if (position < getFirstOperationOffset()) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + getFirstOperationOffset() + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
@Override protected void readBytes(ByteBuffer targetBuffer, long position) throws IOException { if (position + targetBuffer.remaining() > getWrittenOffset()) { synchronized (this) { // we only flush here if it's really really needed - try to minimize the impact of the read operation // in some cases ie. a tragic event we might still be able to read the relevant value // which is not really important in production but some test can make most strict assumptions // if we don't fail in this call unless absolutely necessary. if (position + targetBuffer.remaining() > getWrittenOffset()) { outputStream.flush(); } } } // we don't have to have a lock here because we only write ahead to the file, so all writes has been complete // for the requested location. Channels.readFromFileChannelWithEofException(channel, position, targetBuffer); }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "], generation: [" + getGeneration() + "], path: [" + path + "]"); } if (position < getFirstOperationOffset()) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + getFirstOperationOffset() + "], generation: [" + getGeneration() + "], path: [" + path + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "], generation: [" + getGeneration() + "], path: [" + path + "]"); } if (position < getFirstOperationOffset()) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + getFirstOperationOffset() + "], generation: [" + getGeneration() + "], path: [" + path + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
/** * reads an operation at the given position into the given buffer. */ protected void readBytes(ByteBuffer buffer, long position) throws IOException { if (position >= length) { throw new EOFException("read requested past EOF. pos [" + position + "] end: [" + length + "], generation: [" + getGeneration() + "], path: [" + path + "]"); } if (position < getFirstOperationOffset()) { throw new IOException("read requested before position of first ops. pos [" + position + "] first op on: [" + getFirstOperationOffset() + "], generation: [" + getGeneration() + "], path: [" + path + "]"); } Channels.readFromFileChannelWithEofException(channel, position, buffer); }
@Override protected void readBytes(ByteBuffer targetBuffer, long position) throws IOException { try { if (position + targetBuffer.remaining() > getWrittenOffset()) { synchronized (this) { // we only flush here if it's really really needed - try to minimize the impact of the read operation // in some cases ie. a tragic event we might still be able to read the relevant value // which is not really important in production but some test can make most strict assumptions // if we don't fail in this call unless absolutely necessary. if (position + targetBuffer.remaining() > getWrittenOffset()) { outputStream.flush(); } } } } catch (final Exception ex) { closeWithTragicEvent(ex); throw ex; } // we don't have to have a lock here because we only write ahead to the file, so all writes has been complete // for the requested location. Channels.readFromFileChannelWithEofException(channel, position, targetBuffer); }
@Override protected void readBytes(ByteBuffer targetBuffer, long position) throws IOException { try { if (position + targetBuffer.remaining() > getWrittenOffset()) { synchronized (this) { // we only flush here if it's really really needed - try to minimize the impact of the read operation // in some cases ie. a tragic event we might still be able to read the relevant value // which is not really important in production but some test can make most strict assumptions // if we don't fail in this call unless absolutely necessary. if (position + targetBuffer.remaining() > getWrittenOffset()) { outputStream.flush(); } } } } catch (final Exception ex) { closeWithTragicEvent(ex); throw ex; } // we don't have to have a lock here because we only write ahead to the file, so all writes has been complete // for the requested location. Channels.readFromFileChannelWithEofException(channel, position, targetBuffer); }