public void write(final LittleEndianOutputStream dos) throws IOException { // Chr name, binSize, # bins, longest feature dos.writeString(name); dos.writeInt(binWidth); dos.writeInt(blocks.size()); dos.writeInt(longestFeature); dos.writeInt(0); // no longer used //dos.writeInt(largestBlockSize); dos.writeInt(nFeatures); long pos = 0; long size = 0; for (final Block block : blocks) { pos = block.getStartPosition(); size = block.getSize(); dos.writeLong(pos); } // End of last block for this chromosome dos.writeLong(pos + size); }
/** * @param los It is assumes that caller has done appropriate buffering and BlockCompressedOutputStream wrapping. * Caller should close output stream after invoking this method. * @throws IOException */ @Override public void write(final LittleEndianOutputStream los) throws IOException { los.writeInt(MAGIC_NUMBER); los.writeInt(sequenceNames.size()); los.writeInt(formatSpec.flags); los.writeInt(formatSpec.sequenceColumn); los.writeInt(formatSpec.startPositionColumn); los.writeInt(formatSpec.endPositionColumn); los.writeInt(formatSpec.metaCharacter); los.writeInt(formatSpec.numHeaderLinesToSkip); int nameBlockSize = sequenceNames.size(); // null terminators for (final String sequenceName : sequenceNames) nameBlockSize += sequenceName.length(); los.writeInt(nameBlockSize); for (final String sequenceName : sequenceNames) { los.write(StringUtil.stringToBytes(sequenceName)); los.write(0); } for (final BinningIndexContent index : indices) { writeSequence(index, los); } }
/** * Srite a string as a null terminated byte array. * * @param s * @throws IOException */ public void writeString(String s) throws IOException { writeBytes(s); write((byte) 0); }
@Override public void writeBasedOnFeatureFile(final File featureFile) throws IOException { if (!featureFile.isFile()) return; final LittleEndianOutputStream idxStream = new LittleEndianOutputStream(new FileOutputStream(Tribble.indexFile(featureFile))); write(idxStream); idxStream.close(); }
static void createTestFile() throws IOException { LittleEndianOutputStream los = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream("les_test.bin"))); los.writeString("Binary test file"); los.writeFloat(Float.MAX_VALUE); los.writeByte(Byte.MAX_VALUE); los.writeShort(Short.MAX_VALUE); los.writeInt(Integer.MAX_VALUE); los.writeLong(Long.MAX_VALUE); los.writeDouble(Double.MAX_VALUE); los.close(); } }
private void writeLinearIndex(final LinearIndex linearIndex, final LittleEndianOutputStream los) throws IOException { if (linearIndex.getIndexStart() != 0) { // This could be handled by writing zeroes, but it is not expected so just fail. throw new IllegalArgumentException("Non-zero linear index start"); } final long[] entries = linearIndex.getIndexEntries(); los.writeInt(entries.length); for (final long entry : entries) los.writeLong(entry); }
@Override public void write(final Path idxPath) throws IOException { try(final LittleEndianOutputStream idxStream = new LittleEndianOutputStream(new BufferedOutputStream(Files.newOutputStream(idxPath)))) { write(idxStream); } }
public final void writeFloat(float f) throws IOException { this.writeInt(Float.floatToIntBits(f)); }
public final void writeDouble(double d) throws IOException { this.writeLong(Double.doubleToLongBits(d)); }
/** * Write the index to a file; little endian. * @param idx * @param idxFile * @throws IOException */ public static void writeIndex(final Index idx, final File idxFile) throws IOException { LittleEndianOutputStream stream = null; try { stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile))); idx.write(stream); } finally { if(stream != null) { stream.close(); } } }
private void writeBin(final Bin bin, final LittleEndianOutputStream los) throws IOException { los.writeInt(bin.getBinNumber()); final List<Chunk> chunkList = bin.getChunkList(); los.writeInt(chunkList.size()); for (final Chunk chunk: chunkList) { los.writeLong(chunk.getChunkStart()); los.writeLong(chunk.getChunkEnd()); } }
@Override public void write(final Path idxPath) throws IOException { try(final LittleEndianOutputStream idxStream = new LittleEndianOutputStream(new BufferedOutputStream(Files.newOutputStream(idxPath)))) { write(idxStream); } }
public final void writeFloat(float f) throws IOException { this.writeInt(Float.floatToIntBits(f)); }
public final void writeDouble(double d) throws IOException { this.writeLong(Double.doubleToLongBits(d)); }
public static void writeTribbleIndex(Index idx, String idxFile) throws IOException { LittleEndianOutputStream stream = null; try { stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile))); idx.write(stream); } catch (Exception e) { log.error(e.getMessage(), e); // Delete output file as its probably corrupt File tmp = new File(idxFile); if (tmp.exists()) { tmp.delete(); } } finally { if (stream != null) { stream.close(); } } }
/** * write the header to the target output stream * * @param dos the little endian output stream * @throws IOException an exception when we can't write to the file */ private void writeHeader(final LittleEndianOutputStream dos) throws IOException { dos.writeInt(MAGIC_NUMBER); dos.writeInt(getType()); dos.writeInt(version); dos.writeString(indexedFile.getAbsolutePath()); dos.writeLong(indexedFileSize); dos.writeLong(indexedFileTS); dos.writeString(indexedFileMD5); dos.writeInt(flags); // Properties (Version 3 and later) dos.writeInt(properties.size()); for (final Map.Entry<String, String> prop : properties.entrySet()) { dos.writeString(prop.getKey()); dos.writeString(prop.getValue()); } }
private void writeBin(final Bin bin, final LittleEndianOutputStream los) throws IOException { los.writeInt(bin.getBinNumber()); final List<Chunk> chunkList = bin.getChunkList(); los.writeInt(chunkList.size()); for (final Chunk chunk : chunkList) { los.writeLong(chunk.getChunkStart()); los.writeLong(chunk.getChunkEnd()); } }
/** * Writes the index with BGZF. * * @param tabixPath Where to write the index. */ @Override public void write(final Path tabixPath) throws IOException { try(final LittleEndianOutputStream los = new LittleEndianOutputStream(new BlockCompressedOutputStream(Files.newOutputStream(tabixPath), (Path)null))) { write(los); } }