Skip to content

Commit

Permalink
Add setter for file name to BlockCompressedOutputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
magicDGS committed Mar 9, 2017
1 parent ce693cd commit 1f23883
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public static DeflaterFactory getDefaultDeflaterFactory() {
private final Deflater noCompressionDeflater = new Deflater(Deflater.NO_COMPRESSION, true);
private final CRC32 crc32 = new CRC32();
private File file = null;
private String fileName = null;
private long mBlockAddress = 0;


Expand Down Expand Up @@ -161,6 +162,7 @@ public BlockCompressedOutputStream(final File file, final int compressionLevel)
*/
public BlockCompressedOutputStream(final File file, final int compressionLevel, final DeflaterFactory deflaterFactory) {
this.file = file;
this.fileName = file.getAbsolutePath();
codec = new BinaryCodec(file, true);
deflater = deflaterFactory.makeDeflater(compressionLevel, true);
log.debug("Using deflater: " + deflater.getClass().getSimpleName());
Expand Down Expand Up @@ -196,7 +198,8 @@ public BlockCompressedOutputStream(final OutputStream os, final File file, final
this.file = file;
codec = new BinaryCodec(os);
if (file != null) {
codec.setOutputFileName(file.getAbsolutePath());
fileName = file.getAbsolutePath();
codec.setOutputFileName(fileName);
}
deflater = deflaterFactory.makeDeflater(compressionLevel, true);
log.debug("Using deflater: " + deflater.getClass().getSimpleName());
Expand All @@ -217,6 +220,19 @@ public static BlockCompressedOutputStream maybeBgzfWrapOutputStream(final File l
}
}

/**
* Sets the file name if it is not already set.
* @throws IllegalStateException if the file name was already set.
* @param fileName the filename.
*/
public void setFileName(final String fileName) {
if (this.fileName != null) {
throw new IllegalStateException("File name is already set: " + this.fileName);
}
this.fileName = fileName;
codec.setOutputFileName(fileName);
}

/**
* Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b)
* is that it should have exactly the same effect as the call write(b, 0, b.length).
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/htsjdk/tribble/index/tabix/TabixIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ public TabixFormat getFormatSpec() {
*/
@Override
public void write(final Path tabixPath) throws IOException {
try(final LittleEndianOutputStream los = new LittleEndianOutputStream(new BlockCompressedOutputStream(Files.newOutputStream(tabixPath), null))) {
write(los);
try(final BlockCompressedOutputStream bcos = new BlockCompressedOutputStream(Files.newOutputStream(tabixPath), null)) {
bcos.setFileName(tabixPath.toUri().toString());
write(new LittleEndianOutputStream(bcos));
}
}

Expand Down

0 comments on commit 1f23883

Please sign in to comment.