@Override public void readBytes(final byte[] bytes) { binaryCodec.readBytes(bytes); }
/** * Read a byte array from the input stream. * * @throws htsjdk.samtools.util.RuntimeEOFException if fewer than buffer.length bytes to read */ public void readBytes(final byte[] buffer) { readBytes(buffer, 0, buffer.length); }
/** * Read a byte array from the input stream. * * @throws htsjdk.samtools.util.RuntimeEOFException if fewer than buffer.length bytes to read */ public void readBytes(final byte[] buffer) { readBytes(buffer, 0, buffer.length); }
/** * Read a byte array from the input stream. * * @throws htsjdk.samtools.util.RuntimeEOFException if fewer than buffer.length bytes to read */ public void readBytes(final byte[] buffer) { readBytes(buffer, 0, buffer.length); }
private void readByteBuffer(final int numBytes) { assert(numBytes <= byteBuffer.capacity()); readBytes(byteBuffer.array(), 0, numBytes); byteBuffer.limit(byteBuffer.capacity()); byteBuffer.position(numBytes); }
private void readByteBuffer(final int numBytes) { assert(numBytes <= byteBuffer.capacity()); readBytes(byteBuffer.array(), 0, numBytes); byteBuffer.limit(byteBuffer.capacity()); byteBuffer.position(numBytes); }
private void readByteBuffer(final int numBytes) { assert(numBytes <= byteBuffer.capacity()); readBytes(byteBuffer.array(), 0, numBytes); byteBuffer.limit(byteBuffer.capacity()); byteBuffer.position(numBytes); }
/** * Read a string off the input stream, as ASCII bytes * * @param length length of string to read * @return String read from stream */ public String readString(final int length) { final byte[] buffer; // Recycle single buffer if possible if (length <= scratchBuffer.length) { buffer = scratchBuffer; } else { buffer = new byte[length]; } readBytes(buffer, 0, length); return StringUtil.bytesToString(buffer, 0, length); }
/** * Read a string off the input stream, as ASCII bytes * * @param length length of string to read * @return String read from stream */ public String readString(final int length) { final byte[] buffer; // Recycle single buffer if possible if (length <= scratchBuffer.length) { buffer = scratchBuffer; } else { buffer = new byte[length]; } readBytes(buffer, 0, length); return StringUtil.bytesToString(buffer, 0, length); }
/** * Read a string off the input stream, as ASCII bytes * * @param length length of string to read * @return String read from stream */ public String readString(final int length) { final byte[] buffer; // Recycle single buffer if possible if (length <= scratchBuffer.length) { buffer = scratchBuffer; } else { buffer = new byte[length]; } readBytes(buffer, 0, length); return StringUtil.bytesToString(buffer, 0, length); }
private static Header readHeader(final BinaryCodec binaryCodec) { final byte[] buffer = new byte[SBI_MAGIC.length]; binaryCodec.readBytes(buffer); if (!Arrays.equals(buffer, SBI_MAGIC)) { throw new RuntimeException("Invalid file header in SBI: " + new String(buffer) + " (" + Arrays.toString(buffer) + ")"); } final long fileLength = binaryCodec.readLong(); final byte[] md5 = new byte[16]; binaryCodec.readBytes(md5); final byte[] uuid = new byte[16]; binaryCodec.readBytes(uuid); final long totalNumberOfRecords = binaryCodec.readLong(); final long granularity = binaryCodec.readLong(); return new Header(fileLength, md5, uuid, totalNumberOfRecords, granularity); }
private static Header readHeader(final BinaryCodec binaryCodec) { final byte[] buffer = new byte[SBI_MAGIC.length]; binaryCodec.readBytes(buffer); if (!Arrays.equals(buffer, SBI_MAGIC)) { throw new RuntimeException("Invalid file header in SBI: " + new String(buffer) + " (" + Arrays.toString(buffer) + ")"); } final long fileLength = binaryCodec.readLong(); final byte[] md5 = new byte[16]; binaryCodec.readBytes(md5); final byte[] uuid = new byte[16]; binaryCodec.readBytes(uuid); final long totalNumberOfRecords = binaryCodec.readLong(); final long granularity = binaryCodec.readLong(); return new Header(fileLength, md5, uuid, totalNumberOfRecords, granularity); }
@Test public void testReadAndWrite() throws IOException { final byte[] value = new byte[2]; value[0] = 1; value[1] = 2; //Writing to file final File outputFile = File.createTempFile(TEST_BASENAME, ".bin"); outputFile.deleteOnExit(); final OutputStream stream = new FileOutputStream(outputFile); final BinaryCodec codec = new BinaryCodec(stream); codec.writeBytes(value); codec.close(); //Reading from file final byte[] valuesTwo = new byte[2]; valuesTwo[0] = 1; valuesTwo[1] = 2; final InputStream instream = new FileInputStream(outputFile); final BinaryCodec readCodec = new BinaryCodec(instream); final byte[] bytesFromBinaryFile = new byte[2]; readCodec.readBytes(bytesFromBinaryFile); Assert.assertEquals(valuesTwo, bytesFromBinaryFile); readCodec.close(); outputFile.delete(); }
stream.readBytes(buffer); if (!Arrays.equals(buffer, "BAM\1".getBytes())) { throw new IOException("Invalid BAM file header");
stream.readBytes(buffer); if (!Arrays.equals(buffer, BAMFileConstants.BAM_MAGIC)) { throw new IOException("Invalid BAM file header");
stream.readBytes(buffer); if (!Arrays.equals(buffer, BAMFileConstants.BAM_MAGIC)) { throw new IOException("Invalid BAM file header");
public SAMRecord decode(final int recordLength) { if (recordLength < BAMFileConstants.FIXED_BLOCK_SIZE) { throw new SAMFormatException("Invalid record length: " + recordLength); } final int referenceID = this.binaryCodec.readInt(); final int coordinate = this.binaryCodec.readInt() + 1; final short readNameLength = this.binaryCodec.readUByte(); final short mappingQuality = this.binaryCodec.readUByte(); final int bin = this.binaryCodec.readUShort(); final int cigarLen = this.binaryCodec.readUShort(); final int flags = this.binaryCodec.readUShort(); final int readLen = this.binaryCodec.readInt(); final int mateReferenceID = this.binaryCodec.readInt(); final int mateCoordinate = this.binaryCodec.readInt() + 1; final int insertSize = this.binaryCodec.readInt(); final byte[] restOfRecord = new byte[recordLength - BAMFileConstants.FIXED_BLOCK_SIZE]; this.binaryCodec.readBytes(restOfRecord); final BAMRecord ret = this.samRecordFactory.createBAMRecord( header, referenceID, coordinate, readNameLength, mappingQuality, bin, cigarLen, flags, readLen, mateReferenceID, mateCoordinate, insertSize, restOfRecord); if (null != header) { // don't reset a null header as this will clobber the reference and mate reference indices ret.setHeader(header); } return ret; } }
final int insertSize = this.binaryCodec.readInt(); final byte[] restOfRecord = new byte[recordLength - BAMFileConstants.FIXED_BLOCK_SIZE]; this.binaryCodec.readBytes(restOfRecord); final BAMRecord ret = this.samRecordFactory.createBAMRecord( header, referenceID, coordinate, readNameLength, mappingQuality,
final int insertSize = this.binaryCodec.readInt(); final byte[] restOfRecord = new byte[recordLength - BAMFileConstants.FIXED_BLOCK_SIZE]; this.binaryCodec.readBytes(restOfRecord); final BAMRecord ret = this.samRecordFactory.createBAMRecord( header, referenceID, coordinate, readNameLength, mappingQuality,
final int insertSize = this.binaryCodec.readInt(); final byte[] restOfRecord = new byte[recordLength - BAMFileConstants.FIXED_BLOCK_SIZE]; this.binaryCodec.readBytes(restOfRecord); final BAMRecord ret = this.samRecordFactory.createBAMRecord( header, referenceID, coordinate, readNameLength, mappingQuality,