private boolean isValid() { if (this.block.length < MINIMUM_SIZE || Bytes.littleEndianValue(this.block, this.offset + 0, 4) != SIGNATURE) { return false; } // Total size must be the structure size + comment long commentLength = Bytes.littleEndianValue(this.block, this.offset + COMMENT_LENGTH_OFFSET, 2); return this.size == MINIMUM_SIZE + commentLength; }
@Override public int getMethod() { return (int) Bytes.littleEndianValue(this.header, this.headerOffset + 10, 2); }
@Override public long getCompressedSize() { return Bytes.littleEndianValue(this.header, this.headerOffset + 20, 4); }
@Override public long getSize() { return Bytes.littleEndianValue(this.header, this.headerOffset + 24, 4); }
public long getCrc() { return Bytes.littleEndianValue(this.header, this.headerOffset + 16, 4); }
/** * Return the number of ZIP entries in the file. * @return the number of records in the zip */ public int getNumberOfRecords() { long numberOfRecords = Bytes.littleEndianValue(this.block, this.offset + 10, 2); if (numberOfRecords == 0xFFFF) { throw new IllegalStateException("Zip64 archives are not supported"); } return (int) numberOfRecords; }
/** * Returns the location in the data that the archive actually starts. For most files * the archive data will start at 0, however, it is possible to have prefixed bytes * (often used for startup scripts) at the beginning of the data. * @param data the source data * @return the offset within the data where the archive begins */ public long getStartOfArchive(RandomAccessData data) { long length = Bytes.littleEndianValue(this.block, this.offset + 12, 4); long specifiedOffset = Bytes.littleEndianValue(this.block, this.offset + 16, 4); long actualOffset = data.getSize() - this.size - length; return actualOffset - specifiedOffset; }
/** * Return the bytes of the "Central directory" based on the offset indicated in this * record. * @param data the source data * @return the central directory data */ public RandomAccessData getCentralDirectory(RandomAccessData data) { long offset = Bytes.littleEndianValue(this.block, this.offset + 16, 4); long length = Bytes.littleEndianValue(this.block, this.offset + 12, 4); return data.getSubsection(offset, length); }
public long getTime() { long datetime = Bytes.littleEndianValue(this.header, this.headerOffset + 12, 4); return decodeMsDosFormatDateTime(datetime); }
long nameLength = Bytes.littleEndianValue(data, dataOffset + 28, 2); long extraLength = Bytes.littleEndianValue(data, dataOffset + 30, 2); long commentLength = Bytes.littleEndianValue(data, dataOffset + 32, 2); this.localHeaderOffset = Bytes.littleEndianValue(data, dataOffset + 42, 4);
private RandomAccessData getEntryData(FileHeader entry) throws IOException { // aspectjrt-1.7.4.jar has a different ext bytes length in the // local directory to the central directory. We need to re-read // here to skip them RandomAccessData data = this.jarFile.getData(); byte[] localHeader = data.read(entry.getLocalHeaderOffset(), LOCAL_FILE_HEADER_SIZE); long nameLength = Bytes.littleEndianValue(localHeader, 26, 2); long extraLength = Bytes.littleEndianValue(localHeader, 28, 2); return data.getSubsection(entry.getLocalHeaderOffset() + LOCAL_FILE_HEADER_SIZE + nameLength + extraLength, entry.getCompressedSize()); }