InputStream in = readData(Integer.MAX_VALUE, 200); byte[] header = new byte[200]; fillByteArray(header, in); in.close(); for (int i = 200 - 22; i >= 0; i--){ if (header[i] == (byte) (ZipEntry.ENDSIG & 0xff) && get32(header, i) == ZipEntry.ENDSIG){ throw new IOException("Cannot find Zip End Header in file!"); numEntries = get16(header, offset + ZipEntry.ENDTOT); tableLength = get32(header, offset + ZipEntry.ENDSIZ); tableOffset = get32(header, offset + ZipEntry.ENDOFF);
private int readTableEntry(byte[] table, int offset) throws IOException{ if (get32(table, offset) != ZipEntry.CENSIG){ throw new IOException("Central directory error, expected 'PK12'"); int nameLen = get16(table, offset + ZipEntry.CENNAM); int extraLen = get16(table, offset + ZipEntry.CENEXT); int commentLen = get16(table, offset + ZipEntry.CENCOM); int newOffset = offset + ZipEntry.CENHDR + nameLen + extraLen + commentLen; int flags = get16(table, offset + ZipEntry.CENFLG); if ((flags & 1) == 1){ int method = get16(table, offset + ZipEntry.CENHOW); if (method != ZipEntry.DEFLATED && method != ZipEntry.STORED){ String name = getUTF8String(table, offset + ZipEntry.CENHDR, nameLen); if (name.charAt(name.length()-1) == '/'){ entry.name = name; entry.deflate = (method == ZipEntry.DEFLATED); entry.crc = getu32(table, offset + ZipEntry.CENCRC); entry.length = get32(table, offset + ZipEntry.CENLEN); entry.compSize = get32(table, offset + ZipEntry.CENSIZ); entry.offset = get32(table, offset + ZipEntry.CENOFF);
public void setRootPath(String path){ if (!rootPath.equals(path)){ rootPath = path; try { load(new URL(path)); } catch (IOException ex) { logger.log(Level.WARNING, "Failed to set root path "+path, ex); } } }
private void readCentralDirectory() throws IOException{ InputStream in = readData(tableOffset, tableLength); byte[] header = new byte[tableLength]; // Fix for "PK12 bug in town.zip": sometimes // not entire byte array will be read with InputStream.read() // (especially for big headers) fillByteArray(header, in); // in.read(header); in.close(); entries = new HashMap<String, ZipEntry2>(numEntries); int offset = 0; for (int i = 0; i < numEntries; i++){ offset = readTableEntry(header, offset); } }
public void load(URL url) throws IOException { if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https")) throw new UnsupportedOperationException("HttpZipLocator only supports HTTP(S) URLs"); zipUrl = url; readEndHeader(); readCentralDirectory(); }
private InputStream openStream(ZipEntry2 entry) throws IOException{ InputStream in = readData(entry.offset, entry.compSize); if (entry.deflate){ return new InflaterInputStream(in, new Inflater(true)); } return in; }
public InputStream openStream(String name) throws IOException{ ZipEntry2 entry = entries.get(name); if (entry == null) throw new RuntimeException("Entry not found: "+name); return openStream(entry); }
private void readCentralDirectory() throws IOException{ InputStream in = readData(tableOffset, tableLength); byte[] header = new byte[tableLength]; // Fix for "PK12 bug in town.zip": sometimes // not entire byte array will be read with InputStream.read() // (especially for big headers) fillByteArray(header, in); // in.read(header); in.close(); entries = new HashMap<String, ZipEntry2>(numEntries); int offset = 0; for (int i = 0; i < numEntries; i++){ offset = readTableEntry(header, offset); } }
public void load(URL url) throws IOException { if (!url.getProtocol().equals("http")) throw new UnsupportedOperationException(); zipUrl = url; readEndHeader(); readCentralDirectory(); }
private InputStream openStream(ZipEntry2 entry) throws IOException{ InputStream in = readData(entry.offset, entry.compSize); if (entry.deflate){ return new InflaterInputStream(in, new Inflater(true)); } return in; }
public InputStream openStream(String name) throws IOException{ ZipEntry2 entry = entries.get(name); if (entry == null) throw new RuntimeException("Entry not found: "+name); return openStream(entry); }
InputStream in = readData(Integer.MAX_VALUE, 200); byte[] header = new byte[200]; fillByteArray(header, in); in.close(); for (int i = 200 - 22; i >= 0; i--){ if (header[i] == (byte) (ZipEntry.ENDSIG & 0xff) && get32(header, i) == ZipEntry.ENDSIG){ throw new IOException("Cannot find Zip End Header in file!"); numEntries = get16(header, offset + ZipEntry.ENDTOT); tableLength = get32(header, offset + ZipEntry.ENDSIZ); tableOffset = get32(header, offset + ZipEntry.ENDOFF);
private int readTableEntry(byte[] table, int offset) throws IOException{ if (get32(table, offset) != ZipEntry.CENSIG){ throw new IOException("Central directory error, expected 'PK12'"); int nameLen = get16(table, offset + ZipEntry.CENNAM); int extraLen = get16(table, offset + ZipEntry.CENEXT); int commentLen = get16(table, offset + ZipEntry.CENCOM); int newOffset = offset + ZipEntry.CENHDR + nameLen + extraLen + commentLen; int flags = get16(table, offset + ZipEntry.CENFLG); if ((flags & 1) == 1){ int method = get16(table, offset + ZipEntry.CENHOW); if (method != ZipEntry.DEFLATED && method != ZipEntry.STORED){ String name = getUTF8String(table, offset + ZipEntry.CENHDR, nameLen); if (name.charAt(name.length()-1) == '/'){ entry.name = name; entry.deflate = (method == ZipEntry.DEFLATED); entry.crc = getu32(table, offset + ZipEntry.CENCRC); entry.length = get32(table, offset + ZipEntry.CENLEN); entry.compSize = get32(table, offset + ZipEntry.CENSIZ); entry.offset = get32(table, offset + ZipEntry.CENOFF);
private void readCentralDirectory() throws IOException{ InputStream in = readData(tableOffset, tableLength); byte[] header = new byte[tableLength]; // Fix for "PK12 bug in town.zip": sometimes // not entire byte array will be read with InputStream.read() // (especially for big headers) fillByteArray(header, in); // in.read(header); in.close(); entries = new HashMap<String, ZipEntry2>(numEntries); int offset = 0; for (int i = 0; i < numEntries; i++){ offset = readTableEntry(header, offset); } }
public void load(URL url) throws IOException { if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https")) throw new UnsupportedOperationException("HttpZipLocator only supports HTTP(S) URLs"); zipUrl = url; readEndHeader(); readCentralDirectory(); }
private InputStream openStream(ZipEntry2 entry) throws IOException{ InputStream in = readData(entry.offset, entry.compSize); if (entry.deflate){ return new InflaterInputStream(in, new Inflater(true)); } return in; }
public InputStream openStream(String name) throws IOException{ ZipEntry2 entry = entries.get(name); if (entry == null) throw new RuntimeException("Entry not found: "+name); return openStream(entry); }
public void setRootPath(String path){ if (!rootPath.equals(path)){ rootPath = path; try { load(new URL(path)); } catch (IOException ex) { logger.log(Level.WARNING, "Failed to set root path "+path, ex); } } }
InputStream in = readData(Integer.MAX_VALUE, 200); byte[] header = new byte[200]; fillByteArray(header, in); in.close(); for (int i = 200 - 22; i >= 0; i--){ if (header[i] == (byte) (ZipEntry.ENDSIG & 0xff) && get32(header, i) == ZipEntry.ENDSIG){ throw new IOException("Cannot find Zip End Header in file!"); numEntries = get16(header, offset + ZipEntry.ENDTOT); tableLength = get32(header, offset + ZipEntry.ENDSIZ); tableOffset = get32(header, offset + ZipEntry.ENDOFF);
private int readTableEntry(byte[] table, int offset) throws IOException{ if (get32(table, offset) != ZipEntry.CENSIG){ throw new IOException("Central directory error, expected 'PK12'"); int nameLen = get16(table, offset + ZipEntry.CENNAM); int extraLen = get16(table, offset + ZipEntry.CENEXT); int commentLen = get16(table, offset + ZipEntry.CENCOM); int newOffset = offset + ZipEntry.CENHDR + nameLen + extraLen + commentLen; int flags = get16(table, offset + ZipEntry.CENFLG); if ((flags & 1) == 1){ int method = get16(table, offset + ZipEntry.CENHOW); if (method != ZipEntry.DEFLATED && method != ZipEntry.STORED){ String name = getUTF8String(table, offset + ZipEntry.CENHDR, nameLen); if (name.charAt(name.length()-1) == '/'){ entry.name = name; entry.deflate = (method == ZipEntry.DEFLATED); entry.crc = getu32(table, offset + ZipEntry.CENCRC); entry.length = get32(table, offset + ZipEntry.CENLEN); entry.compSize = get32(table, offset + ZipEntry.CENSIZ); entry.offset = get32(table, offset + ZipEntry.CENOFF);