import java.io.*; public class ZDecodes extends FilterInputStream { /** * @param is the input stream to decompress * @exception IOException if the header is malformed */ public ZDecodes(InputStream is) throws IOException { super(is); parse_header(); } byte[] one = new byte[1]; public synchronized int read() throws IOException { int b = in.read(one, 0, 1); if (b == 1) return (one[0] & 0xff); else return -1; } // string table stuff private static final int TBL_CLEAR = 0x100; private static final int TBL_FIRST = TBL_CLEAR + 1; private int[] tab_prefix; private byte[] tab_suffix; private int[] zeros = new int[256]; private byte[] stack; // various state private boolean block_mode; private int n_bits; private int maxbits; private int maxmaxcode; private int maxcode; private int bitmask; private int oldcode; private byte finchar; private int stackp; private int free_ent; // input buffer private byte[] data = new byte[10000]; private int bit_pos = 0, end = 0, got = 0; private boolean eof = false; private static final int EXTRA = 64; public synchronized int read(byte[] buf, int off, int len) throws IOException { if (eof) return -1; int start = off; /* Using local copies of various variables speeds things up by as * much as 30% ! */ int[] l_tab_prefix = tab_prefix; byte[] l_tab_suffix = tab_suffix; byte[] l_stack = stack; int l_n_bits = n_bits; int l_maxcode = maxcode; int l_maxmaxcode = maxmaxcode; int l_bitmask = bitmask; int l_oldcode = oldcode; byte l_finchar = finchar; int l_stackp = stackp; int l_free_ent = free_ent; byte[] l_data = data; int l_bit_pos = bit_pos; // empty stack if stuff still left int s_size = l_stack.length - l_stackp; if (s_size > 0) { int num = (s_size >= len) ? len : s_size ; System.arraycopy(l_stack, l_stackp, buf, off, num); off += num; len -= num; l_stackp += num; } if (len == 0) { stackp = l_stackp; return off-start; } // loop, filling local buffer until enough data has been decompressed main_loop: do { if (end < EXTRA) fill(); int bit_in = (got > 0) ? (end - end%l_n_bits)<<3 : (end<<3)-(l_n_bits-1); while (l_bit_pos < bit_in) { // check for code-width expansion if (l_free_ent > l_maxcode) { int n_bytes = l_n_bits << 3; l_bit_pos = (l_bit_pos-1) + n_bytes - (l_bit_pos-1+n_bytes) % n_bytes; l_n_bits++; l_maxcode = (l_n_bits==maxbits) ? l_maxmaxcode : (1<<l_n_bits) - 1; if (debug) System.err.println("Code-width expanded to " + l_n_bits); l_bitmask = (1<<l_n_bits)-1; l_bit_pos = resetbuf(l_bit_pos); continue main_loop; } // read next code int pos = l_bit_pos>>3; int code = (((l_data[pos]&0xFF) | ((l_data[pos+1]&0xFF)<<8) | ((l_data[pos+2]&0xFF)<<16)) >> (l_bit_pos & 0x7)) & l_bitmask; l_bit_pos += l_n_bits; // handle first iteration if (l_oldcode == -1) { if (code >= 256) throw new IOException("corrupt input: " + code + " > 255"); l_finchar = (byte) (l_oldcode = code); buf[off++] = l_finchar; len--; continue; } // handle CLEAR code if (code == TBL_CLEAR && block_mode) { System.arraycopy(zeros, 0, l_tab_prefix, 0, zeros.length); l_free_ent = TBL_FIRST - 1; int n_bytes = l_n_bits << 3; l_bit_pos = (l_bit_pos-1) + n_bytes - (l_bit_pos-1+n_bytes) % n_bytes; l_n_bits = INIT_BITS; l_maxcode = (1 << l_n_bits) - 1; l_bitmask = l_maxcode; if (debug) System.err.println("Code tables reset"); l_bit_pos = resetbuf(l_bit_pos); continue main_loop; } // setup int incode = code; l_stackp = l_stack.length; // Handle KwK case if (code >= l_free_ent) { if (code > l_free_ent) throw new IOException("corrupt input: code=" + code + ", free_ent=" + l_free_ent); l_stack[--l_stackp] = l_finchar; code = l_oldcode; } // Generate output characters in reverse order while (code >= 256) { l_stack[--l_stackp] = l_tab_suffix[code]; code = l_tab_prefix[code]; } l_finchar = l_tab_suffix[code]; buf[off++] = l_finchar; len--; // And put them out in forward order s_size = l_stack.length - l_stackp; int num = (s_size >= len) ? len : s_size ; System.arraycopy(l_stack, l_stackp, buf, off, num); off += num; len -= num; l_stackp += num; // generate new entry in table if (l_free_ent < l_maxmaxcode) { l_tab_prefix[l_free_ent] = l_oldcode; l_tab_suffix[l_free_ent] = l_finchar; l_free_ent++; } // Remember previous code l_oldcode = incode; // if output buffer full, then return if (len == 0) { n_bits = l_n_bits; maxcode = l_maxcode; bitmask = l_bitmask; oldcode = l_oldcode; finchar = l_finchar; stackp = l_stackp; free_ent = l_free_ent; bit_pos = l_bit_pos; return off-start; } } l_bit_pos = resetbuf(l_bit_pos); } while (got > 0); n_bits = l_n_bits; maxcode = l_maxcode; bitmask = l_bitmask; oldcode = l_oldcode; finchar = l_finchar; stackp = l_stackp; free_ent = l_free_ent; bit_pos = l_bit_pos; eof = true; return off-start; } /** * Moves the unread data in the buffer to the beginning and resets * the pointers. */ private final int resetbuf(int bit_pos) { int pos = bit_pos >> 3; System.arraycopy(data, pos, data, 0, end-pos); end -= pos; return 0; } private final void fill() throws IOException { got = in.read(data, end, data.length-1-end); if (got > 0) end += got; } public synchronized long skip(long num) throws IOException { byte[] tmp = new byte[(int) num]; int got = read(tmp, 0, (int) num); if (got > 0) return (long) got; else return 0L; } public synchronized int available() throws IOException { if (eof) return 0; return in.available(); } private static final int LZW_MAGIC = 0x1f9d; private static final int MAX_BITS = 16; private static final int INIT_BITS = 9; private static final int HDR_MAXBITS = 0x1f; private static final int HDR_EXTENDED = 0x20; private static final int HDR_FREE = 0x40; private static final int HDR_BLOCK_MODE = 0x80; private void parse_header() throws IOException { // read in and check magic number int t = in.read(); if (t < 0) throw new EOFException("Failed to read magic number"); int magic = (t & 0xff) << 8; t = in.read(); if (t < 0) throw new EOFException("Failed to read magic number"); magic += t & 0xff; if (magic != LZW_MAGIC) throw new IOException("Input not in compress format (read " + "magic number 0x" + Integer.toHexString(magic) + ")"); // read in header byte int header = in.read(); if (header < 0) throw new EOFException("Failed to read header"); block_mode = (header & HDR_BLOCK_MODE) > 0; maxbits = header & HDR_MAXBITS; if (maxbits > MAX_BITS) throw new IOException("Stream compressed with " + maxbits + " bits, but can only handle " + MAX_BITS + " bits"); if ((header & HDR_EXTENDED) > 0) throw new IOException("Header extension bit set"); if ((header & HDR_FREE) > 0) throw new IOException("Header bit 6 set"); if (debug) { System.err.println("block mode: " + block_mode); System.err.println("max bits: " + maxbits); } // initialize stuff maxmaxcode = 1 << maxbits; n_bits = INIT_BITS; maxcode = (1 << n_bits) - 1; bitmask = maxcode; oldcode = -1; finchar = 0; free_ent = block_mode ? TBL_FIRST : 256; tab_prefix = new int[1 << maxbits]; tab_suffix = new byte[1 << maxbits]; stack = new byte[1 << maxbits]; stackp = stack.length; for (int idx=255; idx>=0; idx--) tab_suffix[idx] = (byte) idx; } private static final boolean debug = false; public static void ZDecodes(String zPath, String oPath) throws Exception{ ZDecodes(zPath,oPath,true); } public static void ZDecodes(String zPath, String oPath,boolean isNeedDelSrc) throws Exception{ OutputStream outputStream = null; InputStream in = null; try { File file = new File(oPath); //解压后的存放路径 if (!file.exists()) file.createNewFile(); outputStream = new FileOutputStream(file); in = new ZDecodes(new FileInputStream(new File(zPath)));//需要解压的文件 byte[] buf = new byte[8192]; while (true) { int got = in.read(buf); if (got < 0) break; outputStream.write(buf, 0, got); } outputStream.flush(); } finally { if (null != outputStream) outputStream.close(); if (null != in) in.close(); } if(isNeedDelSrc){ FileUtils.deleteFile(zPath); } } public static void main (String args[]) throws Exception { /* OutputStream outputStream = null; InputStream in = null; try { File tempFile = new File("D:/XXX.txt.Z");//需要解压的文件 String filepath = "D:/222/XXX.txt";//解压后的存放路径 outputStream = new FileOutputStream((new File(filepath))); in = new ZDecodes(new FileInputStream(tempFile)); byte[] buf = new byte[100000]; int tot = 0; long beg = System.currentTimeMillis(); while (true) { int got = in.read(buf); if (got < 0) break; // System.out.write(buf, 0, got); outputStream.write(buf, 0, got); tot += got; } outputStream.flush(); long end = System.currentTimeMillis(); System.err.println("Time: " + (end-beg)/1000. + " seconds"); } catch (Exception e) { e.printStackTrace(); } finally { if (null != outputStream) outputStream.close(); if (null != in) in.close(); } */ String zPath = "D:/XXX.txt.Z";//需要解压的文件 String oPath = "D:/222/XXX.txt";//解压后的存放路径 ZDecodes.ZDecodes(zPath, oPath); } }
相关推荐
setting.xml文件,修改Maven仓库指向至阿里仓
基于java的玉安农副产品销售系统的开题报告
dev-c++ 6.3版本
基于java的项目监管系统开题报告
基于springboot多彩吉安红色旅游网站源码数据库文档.zip
毕业设计&课设_基于 AFLFast 改进能量分配策略的毕业设计项目,含 Mix Schedule策略设计及测试结果分析.zip
基于springboot办公用品管理系统源码数据库文档.zip
C++调用qml对象Demo
非常漂亮的类Web界面的Delphi设计54ed7-main.zip
VB SQL车辆管理系统是一款基于Visual Basic(VB)编程语言和SQL数据库开发的综合车辆管理工具。该系统集成了车辆信息管理、驾驶员信息管理、车辆调度、维修记录、数据存储与检索、报告生成以及安全权限管理等多个核心功能模块。 源代码部分提供了详细的开发流程和实现方法,涵盖了从数据库设计、界面设计到事件驱动编程、数据访问技术和错误处理等关键技术点。通过该系统,用户可以方便地录入、查询、修改和删除车辆及驾驶员信息,实现车辆信息的实时更新和跟踪。同时,系统还支持生成各类车辆管理相关的报告,帮助用户更好地掌握车辆运营情况。 系统部分则采用了直观易用的用户界面设计,使得用户能够轻松上手并快速完成车辆管理工作。系统还具备强大的数据处理能力和安全性,通过数据备份和系统升级优化等功能,确保数据的完整性和系统的稳定运行。 总体而言,VB SQL车辆管理系统是一款功能全面、易于操作且安全可靠的车辆管理工具,适用于企业和个人进行日常车辆运营和管理。无论是车辆信息的录入、查询还是报告生成,该系统都能够提供高效、便捷的服务,是车辆管理工作的理想选择。
AutoSAR基础学习资源
基于springboot英语学习平台源码数据库文档.zip
数据集,深度学习,密封数据集,马体态数据集
基于java的数字家庭网站开题报告
podman使用国内源镜像加速器
基于springboot+web的留守儿童网站源码数据库文档.zip
基于springboot的智能宾馆预定系统源码数据库文档.zip
GetQzonehistory-main.zip
环境说明:开发语言:Java 框架:springboot JDK版本:JDK1.8 服务器:tomcat7 数据库:mysql 5.7 数据库工具:Navicat 开发软件:eclipse/myeclipse/idea Maven包:Maven 浏览器:谷歌浏览器。 项目经过测试均可完美运行
内容概要:本文档详细介绍了QST公司生产的QMI8A01型号的6轴惯性测量单元的数据表及性能参数。主要内容包括设备特性、操作模式、接口标准(SPI、I2C与I3C),以及各种运动检测原理和技术规格。文中还提到了设备的工作温度范围宽广,内置的大容量FIFO可用于缓冲传感器数据,减少系统功耗。此外,对于器件的安装焊接指导亦有详细介绍。 适合人群:电子工程技术人员、嵌入式开发人员、硬件设计师等。 使用场景及目标:适用于需要精准测量物体空间位置变化的应用场合,如消费电子产品、智能穿戴设备、工业自动化等领域。帮助工程师快速掌握该款IMU的技术要点和应用场景。 其他说明:文档提供了详细的电气连接图表、封装尺寸图解等资料,方便用户进行电路板的设计制作。同时针对特定应用提出了一些优化建议。