• R/O
  • HTTP
  • SSH
  • HTTPS

dictzip-java: Commit


Commit MetaInfo

Revisionca1a29925c653e6a6684f5dc53502890aa41cb7a (tree)
Zeit2022-05-05 13:03:24
AutorHiroshi Miura <miurahr@linu...>
CommiterHiroshi Miura

Log Message

WriteHeader: improve writing bytebuffer

- Use backing byte[] buf for ByteBuffer instance creation
- Use backing byte array to write values and calc CRC

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

Ändern Zusammenfassung

Diff

--- a/dictzip-lib/src/main/java/org/dict/zip/DictZipHeader.java
+++ b/dictzip-lib/src/main/java/org/dict/zip/DictZipHeader.java
@@ -299,7 +299,8 @@ public class DictZipHeader {
299299 headerCrc.reset();
300300 // force Header CRC on
301301 h.setGzipFlag(FHCRC, true);
302- ByteBuffer bb = ByteBuffer.allocate(22).order(ByteOrder.LITTLE_ENDIAN);
302+ byte[] buf = new byte[22];
303+ ByteBuffer bb = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN);
303304 ByteBuffer chunkbb = ByteBuffer.allocate(h.chunkCount * 2).order(ByteOrder.LITTLE_ENDIAN);
304305 bb.putShort((short) GZIP_MAGIC);
305306 bb.put((byte) Deflater.DEFLATED);
@@ -314,13 +315,15 @@ public class DictZipHeader {
314315 bb.putShort((short) h.subfieldVersion);
315316 bb.putShort((short) h.chunkLength);
316317 bb.putShort((short) h.chunkCount);
317- out.write(bb.array());
318+ out.write(buf);
319+ headerCrc.update(buf);
318320 for (int i = 0; i < h.chunkCount; i++) {
319321 DictZipFileUtils.writeShort(out, h.chunks[i]);
320322 chunkbb.putShort((short) h.chunks[i]);
321323 }
322- headerCrc.update(bb.array());
323- headerCrc.update(chunkbb.array());
324+ chunkbb.flip();
325+ headerCrc.update(chunkbb);
326+ //
324327 if (h.gzipFlag.get(FNAME)) {
325328 if (h.filename != null) {
326329 out.write(h.filename.getBytes(CHARSET));
Show on old repository browser