/** * read <i>length</i> bytes from <i>position</i> of a file channel. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read * @return total bytes read or -1 if an attempt was made to read past EOF. The method always tries to read all the bytes * that will fit in the destination byte buffer. */ public static int readFromFileChannel(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { ByteBuffer buffer = ByteBuffer.wrap(dest, destOffset, length); return readFromFileChannel(channel, channelPosition, buffer); }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest, destOffset, length); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + length + "] end: [" + channel.size() + "]"); } }
/** * read from a file channel into a byte buffer, starting at a certain position. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination {@link java.nio.ByteBuffer} to put data in */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, ByteBuffer dest) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + dest.limit() + "] end: [" + channel.size() + "]"); } }
private static void tryReportOldVersionError(final Path path, final FileChannel channel) throws IOException { // Lucene's CodecUtil writes a magic number of 0x3FD76C17 with the header, in binary this looks like: // binary: 0011 1111 1101 0111 0110 1100 0001 0111 // hex : 3 f d 7 6 c 1 7 // // With version 0 of the translog, the first byte is the Operation.Type, which will always be between 0-4, // so we know if we grab the first byte, it can be: // 0x3f => Lucene's magic number, so we can assume it's version 1 or later // 0x00 => version 0 of the translog final byte b1 = Channels.readFromFileChannel(channel, 0, 1)[0]; if (b1 == 0x3f) { // LUCENE_CODEC_HEADER_BYTE throw new TranslogCorruptedException( path.toString(), "translog looks like version 1 or later, but has corrupted header" ); } else if (b1 == 0x00) { // UNVERSIONED_TRANSLOG_HEADER_BYTE throw new IllegalStateException("pre-1.4 translog found [" + path + "]"); } }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read * @return total bytes read or -1 if an attempt was made to read past EOF. The method always tries to read all the bytes * that will fit in the destination byte buffer. */ public static int readFromFileChannel(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { ByteBuffer buffer = ByteBuffer.wrap(dest, destOffset, length); return readFromFileChannel(channel, channelPosition, buffer); }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read * @return total bytes read or -1 if an attempt was made to read past EOF. The method always tries to read all the bytes * that will fit in the destination byte buffer. */ public static int readFromFileChannel(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { ByteBuffer buffer = ByteBuffer.wrap(dest, destOffset, length); return readFromFileChannel(channel, channelPosition, buffer); }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read * @return total bytes read or -1 if an attempt was made to read past EOF. The method always tries to read all the bytes * that will fit in the destination byte buffer. */ public static int readFromFileChannel(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { ByteBuffer buffer = ByteBuffer.wrap(dest, destOffset, length); return readFromFileChannel(channel, channelPosition, buffer); }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read * @return total bytes read or -1 if an attempt was made to read past EOF. The method always tries to read all the bytes * that will fit in the destination byte buffer. */ public static int readFromFileChannel(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { ByteBuffer buffer = ByteBuffer.wrap(dest, destOffset, length); return readFromFileChannel(channel, channelPosition, buffer); }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest, destOffset, length); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + length + "] end: [" + channel.size() + "]"); } }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest, destOffset, length); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + length + "] end: [" + channel.size() + "]"); } }
/** * read from a file channel into a byte buffer, starting at a certain position. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination {@link java.nio.ByteBuffer} to put data in */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, ByteBuffer dest) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + dest.limit() + "] end: [" + channel.size() + "]"); } }
/** * read from a file channel into a byte buffer, starting at a certain position. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination {@link java.nio.ByteBuffer} to put data in */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, ByteBuffer dest) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + dest.limit() + "] end: [" + channel.size() + "]"); } }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest, destOffset, length); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + length + "] end: [" + channel.size() + "]"); } }
/** * read <i>length</i> bytes from <i>position</i> of a file channel. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination byte array to put data in * @param destOffset offset in dest to read into * @param length number of bytes to read */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, byte[] dest, int destOffset, int length) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest, destOffset, length); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + length + "] end: [" + channel.size() + "]"); } }
/** * read from a file channel into a byte buffer, starting at a certain position. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination {@link java.nio.ByteBuffer} to put data in */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, ByteBuffer dest) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + dest.limit() + "] end: [" + channel.size() + "]"); } }
/** * read from a file channel into a byte buffer, starting at a certain position. An EOFException will be thrown if you * attempt to read beyond the end of file. * * @param channel channel to read from * @param channelPosition position to read from * @param dest destination {@link java.nio.ByteBuffer} to put data in */ public static void readFromFileChannelWithEofException(FileChannel channel, long channelPosition, ByteBuffer dest) throws IOException { int read = readFromFileChannel(channel, channelPosition, dest); if (read < 0) { throw new EOFException("read past EOF. pos [" + channelPosition + "] length: [" + dest.limit() + "] end: [" + channel.size() + "]"); } }
private static void tryReportOldVersionError(final Path path, final FileChannel channel) throws IOException { // Lucene's CodecUtil writes a magic number of 0x3FD76C17 with the header, in binary this looks like: // binary: 0011 1111 1101 0111 0110 1100 0001 0111 // hex : 3 f d 7 6 c 1 7 // // With version 0 of the translog, the first byte is the Operation.Type, which will always be between 0-4, // so we know if we grab the first byte, it can be: // 0x3f => Lucene's magic number, so we can assume it's version 1 or later // 0x00 => version 0 of the translog final byte b1 = Channels.readFromFileChannel(channel, 0, 1)[0]; if (b1 == 0x3f) { // LUCENE_CODEC_HEADER_BYTE throw new TranslogCorruptedException( path.toString(), "translog looks like version 1 or later, but has corrupted header" ); } else if (b1 == 0x00) { // UNVERSIONED_TRANSLOG_HEADER_BYTE throw new IllegalStateException("pre-1.4 translog found [" + path + "]"); } }
private static void tryReportOldVersionError(final Path path, final FileChannel channel) throws IOException { // Lucene's CodecUtil writes a magic number of 0x3FD76C17 with the header, in binary this looks like: // binary: 0011 1111 1101 0111 0110 1100 0001 0111 // hex : 3 f d 7 6 c 1 7 // // With version 0 of the translog, the first byte is the Operation.Type, which will always be between 0-4, // so we know if we grab the first byte, it can be: // 0x3f => Lucene's magic number, so we can assume it's version 1 or later // 0x00 => version 0 of the translog final byte b1 = Channels.readFromFileChannel(channel, 0, 1)[0]; if (b1 == 0x3f) { // LUCENE_CODEC_HEADER_BYTE throw new TranslogCorruptedException("translog looks like version 1 or later, but has corrupted header. path:" + path); } else if (b1 == 0x00) { // UNVERSIONED_TRANSLOG_HEADER_BYTE throw new IllegalStateException("pre-1.4 translog found [" + path + "]"); } }