From 61697324ddab85e2e968bec663f592c756f4487e Mon Sep 17 00:00:00 2001 From: damencho Date: Tue, 17 Dec 2024 19:02:39 -0600 Subject: [PATCH] squash: Fix setting end position. It was skipping the void data. --- src/main/java/org/ebml/matroska/MatroskaFileTags.java | 7 ++++--- src/main/java/org/ebml/matroska/MatroskaFileTracks.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/ebml/matroska/MatroskaFileTags.java b/src/main/java/org/ebml/matroska/MatroskaFileTags.java index d420343..97cc250 100644 --- a/src/main/java/org/ebml/matroska/MatroskaFileTags.java +++ b/src/main/java/org/ebml/matroska/MatroskaFileTags.java @@ -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); @@ -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; } diff --git a/src/main/java/org/ebml/matroska/MatroskaFileTracks.java b/src/main/java/org/ebml/matroska/MatroskaFileTracks.java index 7c739e0..8c3169f 100644 --- a/src/main/java/org/ebml/matroska/MatroskaFileTracks.java +++ b/src/main/java/org/ebml/matroska/MatroskaFileTracks.java @@ -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; @@ -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; }