Skip to content

Commit

Permalink
squash: Fix setting end position.
Browse files Browse the repository at this point in the history
It was skipping the void data.
  • Loading branch information
damencho committed Dec 18, 2024
1 parent fb87ddc commit 6169732
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/ebml/matroska/MatroskaFileTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ public long writeTags(final DataWriter ioDW)

// we need to write beyond the void space we have reserved
// copy beginning of file into a temporary file
try (FileDataWriter dw = ((FileDataWriter)ioDW).copyBeginningOfFile())
try (FileDataWriter tmp = ((FileDataWriter)ioDW).copyBeginningOfFile())
{
// write the tags
len = tagsElem.writeElement(dw);
len = tagsElem.writeElement(tmp);

// now let's copy the rest of the original file by first setting the position after the tags
ioDW.seek(myEndPosition);

// copy the rest of the original file
((FileDataWriter)ioDW).copyEndOfFile(dw);
((FileDataWriter)ioDW).copyEndOfFile(tmp);
myEndPosition = myStartPosition + len;

ioDW.seek(myEndPosition);
Expand All @@ -73,6 +73,7 @@ public long writeTags(final DataWriter ioDW)
if (BLOCK_SIZE > tagsElem.getTotalSize() && ioDW.isSeekable())
{
new VoidElement(BLOCK_SIZE - tagsElem.getTotalSize()).writeElement(ioDW);
myEndPosition = ioDW.getFilePointer();
return BLOCK_SIZE;
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/ebml/matroska/MatroskaFileTracks.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public long writeTracks(final DataWriter ioDW)

// we need to write beyond the void space we have reserved
// copy beginning of file into a temporary file
try (FileDataWriter dw = ((FileDataWriter)ioDW).copyBeginningOfFile())
try (FileDataWriter tmp = ((FileDataWriter)ioDW).copyBeginningOfFile())
{
// write the tracks
len = tracksElem.writeElement(dw);
len = tracksElem.writeElement(tmp);

// now let's copy the rest of the original file by first setting the position after the tracks
ioDW.seek(myEndPosition);

// copy the rest of the original file
((FileDataWriter)ioDW).copyEndOfFile(dw);
((FileDataWriter)ioDW).copyEndOfFile(tmp);

myEndPosition = myStartPosition + len;

Expand All @@ -82,6 +82,7 @@ public long writeTracks(final DataWriter ioDW)
if (BLOCK_SIZE > tracksElem.getTotalSize() && ioDW.isSeekable())
{
new VoidElement(BLOCK_SIZE - tracksElem.getTotalSize()).writeElement(ioDW);
myEndPosition = ioDW.getFilePointer();
return BLOCK_SIZE;
}

Expand Down

0 comments on commit 6169732

Please sign in to comment.