/** * Creates a relay that reads a recorded stream from {@code file}. * * <p><strong>Warning:</strong> callers to this method must immediately call {@link #newSource} to * create a source and close that when they're done. Otherwise a handle to {@code file} will be * leaked. */ public static Relay read(File file) throws IOException { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); FileOperator fileOperator = new FileOperator(randomAccessFile.getChannel()); // Read the header. Buffer header = new Buffer(); fileOperator.read(0, header, FILE_HEADER_SIZE); ByteString prefix = header.readByteString(PREFIX_CLEAN.size()); if (!prefix.equals(PREFIX_CLEAN)) throw new IOException("unreadable cache file"); long upstreamSize = header.readLong(); long metadataSize = header.readLong(); // Read the metadata. Buffer metadataBuffer = new Buffer(); fileOperator.read(FILE_HEADER_SIZE + upstreamSize, metadataBuffer, metadataSize); ByteString metadata = metadataBuffer.readByteString(); // Return the result. return new Relay(randomAccessFile, null, upstreamSize, metadata, 0L); }
/** * Creates a relay that reads a recorded stream from {@code file}. * * <p><strong>Warning:</strong> callers to this method must immediately call {@link #newSource} to * create a source and close that when they're done. Otherwise a handle to {@code file} will be * leaked. */ public static Relay read(File file) throws IOException { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); FileOperator fileOperator = new FileOperator(randomAccessFile.getChannel()); // Read the header. Buffer header = new Buffer(); fileOperator.read(0, header, FILE_HEADER_SIZE); ByteString prefix = header.readByteString(PREFIX_CLEAN.size()); if (!prefix.equals(PREFIX_CLEAN)) throw new IOException("unreadable cache file"); long upstreamSize = header.readLong(); long metadataSize = header.readLong(); // Read the metadata. Buffer metadataBuffer = new Buffer(); fileOperator.read(FILE_HEADER_SIZE + upstreamSize, metadataBuffer, metadataSize); ByteString metadata = metadataBuffer.readByteString(); // Return the result. return new Relay(randomAccessFile, null, upstreamSize, metadata, 0L); }
@Override public long readLong() throws IOException { require(8); return buffer.readLong(); }
@Override public long readLongLe() { return Util.reverseBytesLong(readLong()); }
/** * Creates a relay that reads a recorded stream from {@code file}. * * <p><strong>Warning:</strong> callers to this method must immediately call {@link #newSource} to * create a source and close that when they're done. Otherwise a handle to {@code file} will be * leaked. */ public static Relay read(File file) throws IOException { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); FileOperator fileOperator = new FileOperator(randomAccessFile.getChannel()); // Read the header. Buffer header = new Buffer(); fileOperator.read(0, header, FILE_HEADER_SIZE); ByteString prefix = header.readByteString(PREFIX_CLEAN.size()); if (!prefix.equals(PREFIX_CLEAN)) throw new IOException("unreadable cache file"); long upstreamSize = header.readLong(); long metadataSize = header.readLong(); // Read the metadata. Buffer metadataBuffer = new Buffer(); fileOperator.read(FILE_HEADER_SIZE + upstreamSize, metadataBuffer, metadataSize); ByteString metadata = metadataBuffer.readByteString(); // Return the result. return new Relay(randomAccessFile, null, upstreamSize, metadata, 0L); }
/** * Creates a relay that reads a recorded stream from {@code file}. * * <p><strong>Warning:</strong> callers to this method must immediately call {@link #newSource} to * create a source and close that when they're done. Otherwise a handle to {@code file} will be * leaked. */ public static Relay read(File file) throws IOException { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); FileOperator fileOperator = new FileOperator(randomAccessFile.getChannel()); // Read the header. Buffer header = new Buffer(); fileOperator.read(0, header, FILE_HEADER_SIZE); ByteString prefix = header.readByteString(PREFIX_CLEAN.size()); if (!prefix.equals(PREFIX_CLEAN)) throw new IOException("unreadable cache file"); long upstreamSize = header.readLong(); long metadataSize = header.readLong(); // Read the metadata. Buffer metadataBuffer = new Buffer(); fileOperator.read(FILE_HEADER_SIZE + upstreamSize, metadataBuffer, metadataSize); ByteString metadata = metadataBuffer.readByteString(); // Return the result. return new Relay(randomAccessFile, null, upstreamSize, metadata, 0L); }