Class
class CompressInputStream
public class CompressInputStream <: InputStream {
public init(inputStream: InputStream, wrap!: WrapType = DeflateFormat, compressLevel!: CompressLevel = DefaultCompression, bufLen!: Int64 = 512)
}
Description: Compresses an input stream.
A CompressInputStream instance can be bound to any input stream of the InputStream type, and data in the input stream is compressed and output to a byte array.
Parent Type:
init(InputStream, WrapType, CompressLevel, Int64)
public init(inputStream: InputStream, wrap!: WrapType = DeflateFormat, compressLevel!: CompressLevel = DefaultCompression, bufLen!: Int64 = 512)
Description: Constructs an input stream to be compressed.
An input stream must be bound. The compressed data format, compression level, and internal buffer size (data volume to be read from the input stream for compression each time) can be set.
Parameters:
- inputStream: InputStream: input stream to be compressed
- wrap!: WrapType: compressed data format; default value: DeflateFormat
- compressLevel!: CompressLevel: compression level; default value: DefaultCompression
- bufLen!: Int64: size of the input stream buffer; value range: (0, Int64.Max]; default value: 512 bytes
Throws:
- ZlibException: When
bufLen
is less than or equal to 0, memory allocation for the input stream fails, or initialization for the compression resources fails, and this exception is thrown.
func close()
public func close(): Unit
Description: Closes a compression input stream.
After the current CompressInputStream instance is used, this function must be called to release the memory resources occupied by the instance to prevent memory leakage. Before calling this function, ensure that 0 has been returned from the read function. Otherwise, the bound InputStream may not be completely compressed.
Throws:
- ZlibException: If compression resources fail to be released, this exception is thrown.
func read(Array<Byte>)
public func read(outBuf: Array<Byte>): Int64
Description: Reads data from a bound input stream, compresses the data, and stores the compressed data in a specified byte array.
Parameters:
Returns:
- Int64: If the compression is successful, the number of bytes after compression is returned. If the data in the bound input stream is completely compressed or the compression input stream is closed, 0 is returned.
Throws:
- ZlibException: If
outBuf
is empty or data compression fails, this exception is thrown.
class CompressOutputStream
public class CompressOutputStream <: OutputStream {
public init(outputStream: OutputStream, wrap!: WrapType = DeflateFormat, compressLevel!: CompressLevel = DefaultCompression, bufLen!: Int64 = 512)
}
Description: Compresses and writes data to an output stream.
A CompressOutputStream instance can be bound to any output stream of the OutputStream type, and data in a specified byte array is read, compressed, and then output to the bound output stream.
Parent Type:
init(OutputStream, WrapType, CompressLevel, Int64)
public init(outputStream: OutputStream, wrap!: WrapType = DeflateFormat, compressLevel!: CompressLevel = DefaultCompression, bufLen!: Int64 = 512)
Description: Constructs a compression output stream. An output stream must be bound, and the compressed data type, compression level, and internal buffer size (volume of compressed data to be written to the output stream each time) can be set.
Parameters:
- outputStream: OutputStream: bound output stream, to which compressed data is written
- wrap!: WrapType: compressed data format; default value: DeflateFormat
- compressLevel!: CompressLevel: compression level; default value: DefaultCompression
- bufLen!: Int64: size of the output stream buffer; value range: (0, Int64.Max]; default value: 512 bytes
Throws:
- ZlibException: When
bufLen
is less than or equal to 0, memory allocation for the output stream fails, or initialization for the compression resources fails, and this exception is thrown.
func close()
public func close(): Unit
Description: Closes the current compression output stream instance.
When an instance is closed, the remaining compressed data (including the data in the buffer and the compressed tail information) is written to the output stream and the memory resources occupied by the instance are released. After the current compression output stream instance is used, this function must be called to release the memory resources occupied by the instance to prevent memory leakage. Before the close function is called, the data written to the bound output stream is not a complete segment of compressed data. The remaining compressed data is written to the bound output stream only after the close function is called.
Throws:
- ZlibException: If the current compression output stream has been closed or the compression resources fail to be released, this exception is thrown.
func flush()
public func flush(): Unit
Description: Refreshes a compression output stream, specifically, reads the compressed data in the internal buffer, writes the data to the bound output stream, and then refreshes the bound output stream.
Throws:
- ZlibException: If the current compression output stream has been closed, this exception is thrown.
func write(Array<Byte>)
public func write(inBuf: Array<Byte>): Unit
Description: Compresses data in a specified byte array and writes the data to an output stream. When all data is compressed and written to the output stream, the function returns a result.
Parameters:
Throws:
- ZlibException: If the current compression output stream has been closed or the resources fail to be compressed, this exception is thrown.
class DecompressInputStream
public class DecompressInputStream <: InputStream {
public init(inputStream: InputStream, wrap!: WrapType = DeflateFormat, bufLen!: Int64 = 512)
}
Description: Decompresses an input stream.
A DecompressInputStream instance can be bound to any input stream of the InputStream type, and data in the stream is read, decompressed, and then output to a specified byte array.
Parent Type:
init(InputStream, WrapType, Int64)
public init(inputStream: InputStream, wrap!: WrapType = DeflateFormat, bufLen!: Int64 = 512)
Description: Constructs a decompression input stream.
An input stream must be bound. The decompressed data format and internal buffer size (data volume to be read from the input stream for decompression each time) can be set.
Parameters:
- inputStream: InputStream: input stream to be compressed
- wrap!: WrapType: format of the data to be decompressed; default value: DeflateFormat
- bufLen!: Int64: size of the input stream buffer; value range: (0, Int64.Max]; default value: 512 bytes
Throws:
- ZlibException: When
bufLen
is less than or equal to 0, memory allocation for the input stream fails, or initialization for the resources to be decompressed fails, and this exception is thrown.
func close()
public func close(): Unit
Description: Closes a decompression input stream.
After the current DecompressInputStream instance is used, this function must be called to release the memory resources occupied by the instance to prevent memory leakage. Before calling this function, ensure that 0 has been returned from the read function. Otherwise, the bound InputStream may not be completely decompressed.
Throws:
- ZlibException: If resources to be decompressed fail to be released, this exception is thrown.
func read(Array<Byte>)
public func read(outBuf: Array<Byte>): Int64
Description: Reads data from a bound input stream, decompresses the data, and stores the decompressed data in a specified byte array.
Parameters:
Returns:
- Int64: If the decompression is successful, the number of bytes after decompression is returned. If the data in the bound input stream is completely decompressed or the decompression input stream is closed, 0 is returned.
Throws:
- ZlibException: If
outBuf
is empty or data decompression fails, this exception is thrown.
class DecompressOutputStream
public class DecompressOutputStream <: OutputStream {
public init(outputStream: OutputStream, wrap!: WrapType = DeflateFormat, bufLen!: Int64 = 512)
}
Description: Decompresses and writes data to an output stream.
A DecompressOutputStream instance can be bound to a specified output stream of the OutputStream type, and data in a specified byte array is read, decompressed, and then output to the bound output stream.
Parent Type:
init(OutputStream, WrapType, Int64)
public init(outputStream: OutputStream, wrap!: WrapType = DeflateFormat, bufLen!: Int64 = 512)
Description: Constructs a decompression output stream.
An output stream must be bound. The compressed data type, compression level, and internal buffer size can be set. (After decompression, data is stored in the internal buffer. After the buffer is full, data is written to the output stream.)
Parameters:
- outputStream: OutputStream: bound output stream, to which decompressed data is written
- wrap!: WrapType: format of the data to be decompressed; default value: DeflateFormat
- bufLen!: Int64: size of the output stream buffer; value range: (0, Int64.Max]; default value: 512 bytes
Throws:
- ZlibException: When
bufLen
is less than or equal to 0, memory allocation for the output stream fails, or initialization for the resources to be decompressed fails, and this exception is thrown.
func close()
public func close(): Unit
Description: Closes the current decompression output stream instance.
When this instance is closed, the remaining decompressed data is written to the output stream and the memory resources occupied by the instance are released. After the current compression output stream instance is used, this function must be called to release the memory resources occupied by the instance to prevent memory leakage. If the compressed data processed by the write function is incomplete, an exception is thrown due to incomplete decompressed data when the close function is called.
Throws:
- ZlibException: If the current compression output stream has been closed, the data to be decompressed transferred through the write function is incomplete, or the compression resources fail to be released, this exception is thrown.
func flush()
public func flush(): Unit
Description: Refreshes a decompression output stream, specifically, writes the decompressed data in the internal buffer to the bound output stream, and then refreshes the bound output stream.
Throws:
- ZlibException: If the current decompression output stream has been closed, this exception is thrown.
func write(Array<Byte>)
public func write(inBuf: Array<Byte>): Unit
Description: Decompresses data in a specified byte array and writes the data to an output stream. When all data is decompressed and written to the output stream, the function returns a result.
Parameters:
Throws:
- ZlibException: If the current decompression output stream has been closed or the data fails to be decompressed, this exception is thrown.