/** Read data from the connection. If the request hasn't yet been sent to the server, send it. */ public int readInt(byte[] buf, int offset, int length) throws IOException { if (!_didGet) { getConnInput(); } if (_isRequestDone) { return -1; } try { int len = length; if (_isChunked) { if (_chunkLength == 0) { int ch; for (ch = _rs.read(); ch >= 0 && (ch == '\r' || ch == '\n' || ch == ' '); ch = _rs.read()) {} for (; ch >= 0 && ch != '\n'; ch = _rs.read()) { if (ch >= '0' && ch <= '9') _chunkLength = 16 * _chunkLength + ch - '0'; else if (ch >= 'a' && ch <= 'f') _chunkLength = 16 * _chunkLength + ch - 'a' + 10; else if (ch >= 'A' && ch <= 'F') _chunkLength = 16 * _chunkLength + ch - 'A' + 10; } if (_chunkLength == 0) { _isRequestDone = true; return -1; } } else if (_chunkLength < 0) return -1; if (_chunkLength < len) len = _chunkLength; } else if (_contentLength < 0) { } else if (_contentLength == 0) { _isRequestDone = true; return -1; } else if (_contentLength < len) len = _contentLength; len = _rs.read(buf, offset, len); if (len < 0) { } else if (_isChunked) _chunkLength -= len; else if (_contentLength > 0) _contentLength -= len; return len; } catch (IOException e) { _isKeepalive = false; throw e; } catch (RuntimeException e) { _isKeepalive = false; throw e; } }
public boolean next() throws IOException { if (_entries <= _index) return false; _index++; ReadStream is = _is; if (is.readInt() != 0x504b0102) { throw new IOException("illegal zip format"); } is.skip(2 + 2 + 2 + 2 + 2 + 2 + 4); int compressedSize = readInt(is); int uncompressedSize = readInt(is); int nameLen = is.read() + (is.read() << 8); int extraLen = is.read() + (is.read() << 8); int commentLen = is.read() + (is.read() << 8); is.skip(2 + 2 + 4); _localFileOffset = readInt(is); _nameLen = nameLen; if (_cbuf.length < nameLen) _cbuf = new char[nameLen]; char[] cbuf = _cbuf; int k = is.readUTF8ByByteLength(cbuf, 0, nameLen); for (int i = k - 1; i >= 0; i--) { char ch = cbuf[i]; // win32 canonicalize if (ch == '\\') cbuf[i] = '/'; } _name = null; // new String(cbuf, 0, k); if (extraLen + commentLen > 0) is.skip(extraLen + commentLen); return true; }
/** * Creates a new Jar. * * @param path canonical path */ public ZipScanner(Path path) { try { _path = path; int length = (int) path.getLength(); ReadStream is = path.openRead(); try { // PACK200 is a standard comment, so try skipping it first is.skip(length - 22 - 7); if (is.read() != 0x50) { is.skip(6); if (is.read() != 0x50) return; } if (is.read() == 0x4b && is.read() == 0x05 && is.read() == 0x06) { _isValid = true; } if (_isValid) { is.skip(6); _entries = is.read() + (is.read() << 8); is.skip(4); _offset = readInt(is); } } finally { is.close(); } } catch (Exception e) { log().log(Level.FINER, e.toString(), e); } }