Skip to content

Commit

Permalink
Move readHeader/writeHeader check
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Sep 14, 2024
1 parent 5b9981a commit 263cae4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions java/src/main/java/kanzi/io/CompressedInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public CompressedInputStream(InputBitStream ibs, Map<String, Object> ctx)

protected void readHeader() throws IOException
{
if ((this.headless == true) || (this.initialized.getAndSet(true) == true))
return;

// Read stream type
final int type = (int) this.ibs.readBits(32);

Expand Down Expand Up @@ -472,8 +475,7 @@ public int read(byte[] data, int off, int len) throws IOException

private int processBlock() throws IOException
{
if ((this.headless == false) && (this.initialized.getAndSet(true)== false))
this.readHeader();
this.readHeader();

try
{
Expand Down
6 changes: 4 additions & 2 deletions java/src/main/java/kanzi/io/CompressedOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public CompressedOutputStream(OutputBitStream obs, Map<String, Object> ctx)

protected void writeHeader() throws IOException
{
if ((this.headless == true) || (this.initialized.getAndSet(true) == true))
return;

if (this.obs.writeBits(BITSTREAM_TYPE, 32) != 32)
throw new kanzi.io.IOException("Cannot write bitstream type to header", Error.ERR_WRITE_FILE);

Expand Down Expand Up @@ -451,8 +454,7 @@ public void close() throws IOException

private void processBlock() throws IOException
{
if ((this.headless == false) && (this.initialized.getAndSet(true) == false))
this.writeHeader();
this.writeHeader();

if (this.buffers[0].index == 0)
return;
Expand Down

0 comments on commit 263cae4

Please sign in to comment.