ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/compress/LZFOutputStream.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/compress/LZFOutputStream.java
Status
scanned
Type
file
Name
LZFOutputStream.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
2792 (2.7 KB)
MD5
78cf49160f7514bdd4bd1054a20339d4
SHA1
76a7cee4f00c6b713deb5d359ef1a2efe98065da
SHA256
f3afcaee6d4237774f527a0222f6aa6731529bb048915a888522eaa28d48ff55
SHA512

      
    
SHA1_git
f8c97df558545c9f9f50daff64656c8246a3bef6
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
LZFOutputStream.java | 2.7 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.compress; import java.io.IOException; import java.io.OutputStream; import org.h2.engine.Constants; /** * An output stream to write an LZF stream. * The data is automatically compressed. */ public class LZFOutputStream extends OutputStream { /** * The file header of a LZF file. */ static final int MAGIC = ('H' << 24) | ('2' << 16) | ('I' << 8) | 'S'; private final OutputStream out; private final CompressLZF compress = new CompressLZF(); private final byte[] buffer; private int pos; private byte[] outBuffer; public LZFOutputStream(OutputStream out) throws IOException { this.out = out; int len = Constants.IO_BUFFER_SIZE_COMPRESS; buffer = new byte[len]; ensureOutput(len); writeInt(MAGIC); } private void ensureOutput(int len) { // TODO calculate the maximum overhead (worst case) for the output // buffer int outputLen = (len < 100 ? len + 100 : len) * 2; if (outBuffer == null || outBuffer.length < outputLen) { outBuffer = new byte[outputLen]; } } @Override public void write(int b) throws IOException { if (pos >= buffer.length) { flush(); } buffer[pos++] = (byte) b; } private void compressAndWrite(byte[] buff, int len) throws IOException { if (len > 0) { ensureOutput(len); int compressed = compress.compress(buff, 0, len, outBuffer, 0); if (compressed > len) { writeInt(-len); out.write(buff, 0, len); } else { writeInt(compressed); writeInt(len); out.write(outBuffer, 0, compressed); } } } private void writeInt(int x) throws IOException { out.write((byte) (x >> 24)); out.write((byte) (x >> 16)); out.write((byte) (x >> 8)); out.write((byte) x); } @Override public void write(byte[] buff, int off, int len) throws IOException { while (len > 0) { int copy = Math.min(buffer.length - pos, len); System.arraycopy(buff, off, buffer, pos, copy); pos += copy; if (pos >= buffer.length) { flush(); } off += copy; len -= copy; } } @Override public void flush() throws IOException { compressAndWrite(buffer, pos); pos = 0; } @Override public void close() throws IOException { flush(); out.close(); } }
Detected license expression
mpl-2.0 AND epl-1.0
Detected license expression (SPDX)
MPL-2.0 AND EPL-1.0
Percentage of license text
3.01
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License detections License expression License expression SPDX
mpl_2_0_and_epl_1_0-796bf8d7-f485-3520-923d-e6a4b1ecd2f3 mpl-2.0 AND epl-1.0 MPL-2.0 AND EPL-1.0
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220