From 8f053b5cd6ba780e0ed6e9d6e5752015256a8b04 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 11 Jun 2020 17:35:26 +0300 Subject: [PATCH] #35 --- .../java/org/gagravarr/flac/FlacNativeFile.java | 5 ++++- .../gagravarr/ogg/HighLevelOggStreamPacket.java | 14 +++++--------- .../gagravarr/vorbis/VorbisStyleComments.java | 16 +--------------- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/gagravarr/flac/FlacNativeFile.java b/core/src/main/java/org/gagravarr/flac/FlacNativeFile.java index 5bc4e7c..5e380de 100644 --- a/core/src/main/java/org/gagravarr/flac/FlacNativeFile.java +++ b/core/src/main/java/org/gagravarr/flac/FlacNativeFile.java @@ -134,7 +134,9 @@ public InputStream getInputStream() { Vector streams = new Vector<>(); byte[] header = {'f', 'L', 'a', 'C'}; streams.add(new ByteArrayInputStream(header)); - blocksInOrder.stream().forEach(block -> this.addStream(streams, block.getData())); + blocksInOrder.stream().forEach(block -> { + this.addStream(streams, block.getData()); + }); streams.add(input); return new SequenceInputStream(streams.elements()); @@ -154,6 +156,7 @@ public OggStreamPacketDecorator(OggStreamPacket decorated) { } public byte[] getData() { + decorated.write(); return decorated.getData(); } diff --git a/core/src/main/java/org/gagravarr/ogg/HighLevelOggStreamPacket.java b/core/src/main/java/org/gagravarr/ogg/HighLevelOggStreamPacket.java index 02bca91..00bcd90 100644 --- a/core/src/main/java/org/gagravarr/ogg/HighLevelOggStreamPacket.java +++ b/core/src/main/java/org/gagravarr/ogg/HighLevelOggStreamPacket.java @@ -36,14 +36,6 @@ protected OggPacket getOggPacket() { } public byte[] getData() { - return getDecoratedData(); - } - - public void setData(byte[] data) { - this.data = data; - } - - private byte[] getDecoratedData() { if (data != null) { return data; } @@ -53,6 +45,10 @@ private byte[] getDecoratedData() { return null; } + public void setData(byte[] data) { + this.data = data; + } + /** * Returns the approximate number of bytes overhead * from the underlying {@link OggPacket} / {@link OggPage} @@ -70,7 +66,7 @@ public int getOggOverheadSize() { } public OggPacket write() { - this.oggPacket = new OggPacket(getDecoratedData()); + this.oggPacket = new OggPacket(getData()); return this.oggPacket; } } diff --git a/core/src/main/java/org/gagravarr/vorbis/VorbisStyleComments.java b/core/src/main/java/org/gagravarr/vorbis/VorbisStyleComments.java index bd94ee4..2265703 100644 --- a/core/src/main/java/org/gagravarr/vorbis/VorbisStyleComments.java +++ b/core/src/main/java/org/gagravarr/vorbis/VorbisStyleComments.java @@ -42,7 +42,6 @@ public abstract class VorbisStyleComments extends HighLevelOggStreamPacket imple private String vendor; private Map> comments = new HashMap>(); - private boolean modified; public VorbisStyleComments(OggPacket pkt, int dataBeginsAt) { super(pkt); @@ -202,7 +201,6 @@ public List getComments(String tag) { */ public void removeComments(String tag) { comments.remove(normaliseTag(tag)); - this.modified = true; } /** @@ -210,7 +208,6 @@ public void removeComments(String tag) { */ public void removeAllComments() { comments.clear(); - this.modified = true; } /** @@ -222,7 +219,6 @@ public void addComment(String tag, String comment) { comments.put(nt, new ArrayList()); } comments.get(nt).add(comment); - this.modified = true; } /** @@ -235,7 +231,6 @@ public void setComments(String tag, List comments) { this.comments.remove(nt); } this.comments.put(nt, comments); - this.modified = true; } @@ -258,15 +253,6 @@ protected int getInt4(byte[] d, int offset) { return (int) IOUtils.getInt4(d, offset); } - @Override - public byte[] getData() { - if (modified) { -// write(); - modified = false; - } - return super.getData(); - } - @Override public OggPacket write() { // Serialise the comments @@ -307,7 +293,7 @@ public OggPacket write() { // Now fill in the header byte[] data = baos.toByteArray(); - populateMetadataHeader(data, data.length); + populateMetadataHeader(data, data.length - getHeaderSize()); // Record the data setData(data);