Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

109
LINES

< > BotCompany Repo | #1031085 // InflaterInputStream_relaxed - InflaterInputStream that allows incomplete files [abandoned version]

JavaX fragment (include) [tags: use-pretranspiled]

1  
sclass InflaterInputStream_relaxed extends InflaterInputStream {
2  
  *(InputStream in, Inflater inf, int size) {
3  
    super(in, inf, sizee);
4  
  }
5  
6  
  *(InputStream in, Inflater inf) {
7  
    super(in, inf);
8  
  }
9  
10  
  *(InputStream in) {
11  
    super(in);
12  
  }
13  
14  
  public int read(byte[] b, int off, int len) throws IOException {
15  
      ensureOpen();
16  
      if (b == null) {
17  
          throw new NullPointerException();
18  
      } else if (off < 0 || len < 0 || len > b.length - off) {
19  
          throw new IndexOutOfBoundsException();
20  
      } else if (len == 0) {
21  
          return 0;
22  
      }
23  
      try {
24  
          int n;
25  
          while ((n = inf.inflate(b, off, len)) == 0) {
26  
              if (inf.finished() || inf.needsDictionary()) {
27  
                  reachEOF = true;
28  
                  return -1;
29  
              }
30  
              if (inf.needsInput()) {
31  
                if (!fill2())
32  
                  ret -1;
33  
              }
34  
          }
35  
          return n;
36  
      } catch (DataFormatException e) {
37  
          String s = e.getMessage();
38  
          throw new ZipException(s != null ? s : "Invalid ZLIB data format");
39  
      }
40  
  }
41  
42  
  /**
43  
   * Returns 0 after EOF has been reached, otherwise always return 1.
44  
   * <p>
45  
   * Programs should not count on this method to return the actual number
46  
   * of bytes that could be read without blocking.
47  
   *
48  
   * @return     1 before EOF and 0 after EOF.
49  
   * @throws     IOException  if an I/O error occurs.
50  
   *
51  
   */
52  
  public int available() throws IOException {
53  
      ensureOpen();
54  
      if (reachEOF) {
55  
          return 0;
56  
      } else if (inf.finished()) {
57  
          // the end of the compressed data stream has been reached
58  
          reachEOF = true;
59  
          return 0;
60  
      } else {
61  
          return 1;
62  
      }
63  
  }
64  
65  
  private byte[] b = new byte[512];
66  
67  
  /**
68  
   * Skips specified number of bytes of uncompressed data.
69  
   * @param n the number of bytes to skip
70  
   * @return the actual number of bytes skipped.
71  
   * @throws    IOException if an I/O error has occurred
72  
   * @throws    IllegalArgumentException if {@code n < 0}
73  
   */
74  
  public long skip(long n) throws IOException {
75  
      if (n < 0) {
76  
          throw new IllegalArgumentException("negative skip length");
77  
      }
78  
      ensureOpen();
79  
      int max = (int)Math.min(n, Integer.MAX_VALUE);
80  
      int total = 0;
81  
      while (total < max) {
82  
          int len = max - total;
83  
          if (len > b.length) {
84  
              len = b.length;
85  
          }
86  
          len = read(b, 0, len);
87  
          if (len == -1) {
88  
              reachEOF = true;
89  
              break;
90  
          }
91  
          total += len;
92  
      }
93  
      return total;
94  
  }
95  
96  
  /**
97  
   * Fills input buffer with more data to decompress.
98  
   * @throws    IOException if an I/O error has occurred
99  
   * @return true when not at end of stream
100  
   */
101  
  protected bool fill2() throws IOException {
102  
    ensureOpen();
103  
    len = in.read(buf, 0, buf.length);
104  
    if (len == -1)
105  
      false;
106  
    inf.setInput(buf, 0, len);
107  
    true;
108  
  }
109  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031085
Snippet name: InflaterInputStream_relaxed - InflaterInputStream that allows incomplete files [abandoned version]
Eternal ID of this version: #1031085/2
Text MD5: faee426cd57fcc4b87107f378f2450db
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-05-01 00:19:49
Source code size: 3065 bytes / 109 lines
Pitched / IR pitched: No / No
Views / Downloads: 93 / 118
Version history: 1 change(s)
Referenced in: [show references]