本文整理了Java中org.apache.commons.compress.archivers.zip.ZipShort.getValue()
方法的一些代码示例,展示了ZipShort.getValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipShort.getValue()
方法的具体详情如下:
包路径:org.apache.commons.compress.archivers.zip.ZipShort
类名称:ZipShort
方法名:getValue
[英]Get value as Java int.
[中]获取值为javaint。
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Create instance from the two bytes starting at offset.
* @param bytes the bytes to store as a ZipShort
* @param offset the offset to start
*/
public ZipShort (final byte[] bytes, final int offset) {
value = ZipShort.getValue(bytes, offset);
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Override to make two instances with same value equal.
* @param o an object to compare
* @return true if the objects are equal
*/
@Override
public boolean equals(final Object o) {
if (o == null || !(o instanceof ZipShort)) {
return false;
}
return value == ((ZipShort) o).getValue();
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Helper method to get the value as a java int from a two-byte array
* @param bytes the array of bytes
* @return the corresponding java int value
*/
public static int getValue(final byte[] bytes) {
return getValue(bytes, 0);
}
代码示例来源:origin: org.apache.commons/commons-compress
@Override
public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) {
this.rcount = ZipShort.getValue(data, offset);
this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2));
}
}
代码示例来源:origin: org.apache.commons/commons-compress
@Override
public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) {
super.parseFromCentralDirectoryData(data, offset, length);
this.rcount = ZipShort.getValue(data, offset);
this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2));
}
}
代码示例来源:origin: org.apache.commons/commons-compress
@Override
public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws ZipException {
if (length < BASE_SIZE) {
throw new ZipException("Too short content for ResourceAlignmentExtraField (0xa11e): " + length);
}
int alignmentValue = ZipShort.getValue(buffer, offset);
this.alignment = (short) (alignmentValue & (ALLOW_METHOD_MESSAGE_CHANGE_FLAG - 1));
this.allowMethodChange = (alignmentValue & ALLOW_METHOD_MESSAGE_CHANGE_FLAG) != 0;
}
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Parse central directory format.
*
* @param data the buffer to read data from
* @param offset offset into buffer to read data
* @param length the length of data
*/
public void parseCentralDirectoryFormat(final byte[] data, final int offset, final int length) {
this.format = ZipShort.getValue(data, offset);
this.algId = EncryptionAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2));
this.bitlen = ZipShort.getValue(data, offset + 4);
this.flags = ZipShort.getValue(data, offset + 6);
this.rcount = ZipLong.getValue(data, offset + 8);
if (rcount > 0) {
this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 12));
this.hashSize = ZipShort.getValue(data, offset + 14);
// srlist... hashed public keys
for (long i = 0; i < this.rcount; i++) {
for (int j = 0; j < this.hashSize; j++) {
// ZipUtil.signedByteToUnsignedInt(data[offset + 16 + (i * this.hashSize) + j]));
}
}
}
}
代码示例来源:origin: org.apache.commons/commons-compress
final int ivSize = ZipShort.getValue(data, offset);
this.ivData = new byte[ivSize];
System.arraycopy(data, offset + 4, this.ivData, 0, ivSize);
this.format = ZipShort.getValue(data, offset + ivSize + 6);
this.algId = EncryptionAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + ivSize + 8));
this.bitlen = ZipShort.getValue(data, offset + ivSize + 10);
this.flags = ZipShort.getValue(data, offset + ivSize + 12);
final int erdSize = ZipShort.getValue(data, offset + ivSize + 14);
this.erdData = new byte[erdSize];
System.arraycopy(data, offset + ivSize + 16, this.erdData, 0, erdSize);
System.out.println("rcount: " + rcount);
if (rcount == 0) {
final int vSize = ZipShort.getValue(data, offset + ivSize + 20 + erdSize);
this.vData = new byte[vSize - 4];
this.vCRC32 = new byte[4];
System.arraycopy(data, offset + ivSize + 22 + erdSize + vSize - 4, vCRC32, 0, 4);
} else {
this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + ivSize + 20 + erdSize));
this.hashSize = ZipShort.getValue(data, offset + ivSize + 22 + erdSize);
final int resize = ZipShort.getValue(data, offset + ivSize + 24 + erdSize);
this.recipientKeyHash = new byte[this.hashSize];
this.keyBlob = new byte[resize - this.hashSize];
final int vSize = ZipShort.getValue(data, offset + ivSize + 26 + erdSize + resize);
this.vData = new byte[vSize - 4];
代码示例来源:origin: org.apache.commons/commons-compress
/**
* The actual data to put into central directory data - without Header-ID
* or length specifier.
*
* @return the central directory data
*/
@Override
public byte[] getCentralDirectoryData() {
final byte[] centralData = new byte[getCentralDirectoryLength().getValue()];
final byte[] localData = getLocalFileDataData();
// Truncate out create & access time (last 8 bytes) from
// the copy of the local data we obtained:
System.arraycopy(localData, 0, centralData, 0, centralData.length);
return centralData;
}
代码示例来源:origin: org.apache.commons/commons-compress
final int newMode = ZipShort.getValue(tmp, 0);
uid = ZipShort.getValue(tmp, 6);
gid = ZipShort.getValue(tmp, 8);
代码示例来源:origin: org.apache.commons/commons-compress
@Override
public byte[] getCentralDirectoryData() {
final byte[] data = new byte[getCentralDirectoryLength().getValue()];
int off = addSizes(data);
if (relativeHeaderOffset != null) {
System.arraycopy(relativeHeaderOffset.getBytes(), 0, data, off, DWORD);
off += DWORD;
}
if (diskStart != null) {
System.arraycopy(diskStart.getBytes(), 0, data, off, WORD);
off += WORD; // NOSONAR - assignment as documentation
}
return data;
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* The actual data to put into local file data - without Header-ID
* or length specifier.
*
* @return get the data
*/
@Override
public byte[] getLocalFileDataData() {
final byte[] data = new byte[getLocalFileDataLength().getValue()];
int pos = 4;
System.arraycopy(TIME_ATTR_TAG.getBytes(), 0, data, pos, 2);
pos += 2;
System.arraycopy(TIME_ATTR_SIZE.getBytes(), 0, data, pos, 2);
pos += 2;
System.arraycopy(modifyTime.getBytes(), 0, data, pos, 8);
pos += 8;
System.arraycopy(accessTime.getBytes(), 0, data, pos, 8);
pos += 8;
System.arraycopy(createTime.getBytes(), 0, data, pos, 8);
return data;
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* The actual data to put into local file data - without Header-ID
* or length specifier.
*
* @return get the data
*/
@Override
public byte[] getLocalFileDataData() {
final byte[] data = new byte[getLocalFileDataLength().getValue()];
int pos = 0;
data[pos++] = 0;
if (bit0_modifyTimePresent) {
data[0] |= MODIFY_TIME_BIT;
System.arraycopy(modifyTime.getBytes(), 0, data, pos, 4);
pos += 4;
}
if (bit1_accessTimePresent && accessTime != null) {
data[0] |= ACCESS_TIME_BIT;
System.arraycopy(accessTime.getBytes(), 0, data, pos, 4);
pos += 4;
}
if (bit2_createTimePresent && createTime != null) {
data[0] |= CREATE_TIME_BIT;
System.arraycopy(createTime.getBytes(), 0, data, pos, 4);
pos += 4; // NOSONAR - assignment as documentation
}
return data;
}
代码示例来源:origin: org.apache.commons/commons-compress
wordBbuf.flip();
wordBbuf.get(shortBuf);
final int fileNameLen = ZipShort.getValue(shortBuf);
wordBbuf.get(shortBuf);
final int extraFieldLen = ZipShort.getValue(shortBuf);
skipBytes(fileNameLen);
final byte[] localExtraData = new byte[extraFieldLen];
代码示例来源:origin: org.apache.commons/commons-compress
/**
* The actual data to put into local file data - without Header-ID
* or length specifier.
* @return get the data
*/
@Override
public byte[] getLocalFileDataData() {
// CRC will be added later
final byte[] data = new byte[getLocalFileDataLength().getValue() - WORD];
System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2);
final byte[] linkArray = getLinkedFile().getBytes(); // Uses default charset - see class Javadoc
// CheckStyle:MagicNumber OFF
System.arraycopy(ZipLong.getBytes(linkArray.length),
0, data, 2, WORD);
System.arraycopy(ZipShort.getBytes(getUserId()),
0, data, 6, 2);
System.arraycopy(ZipShort.getBytes(getGroupId()),
0, data, 8, 2);
System.arraycopy(linkArray, 0, data, 10, linkArray.length);
// CheckStyle:MagicNumber ON
crc.reset();
crc.update(data);
final long checksum = crc.getValue();
final byte[] result = new byte[data.length + WORD];
System.arraycopy(ZipLong.getBytes(checksum), 0, result, 0, WORD);
System.arraycopy(data, 0, result, WORD, data.length);
return result;
}
代码示例来源:origin: org.apache.commons/commons-compress
sum += element.getLocalFileDataLength().getValue();
代码示例来源:origin: org.apache.commons/commons-compress
sum += element.getCentralDirectoryLength().getValue();
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Populate data from this array as if it was in local file data.
*
* @param data an array of bytes
* @param offset the start offset
* @param length the number of bytes in the array from offset
* @throws java.util.zip.ZipException on error
*/
@Override
public void parseFromLocalFileData(
final byte[] data, int offset, final int length
) throws ZipException {
final int len = offset + length;
// skip reserved
offset += 4;
while (offset + 4 <= len) {
final ZipShort tag = new ZipShort(data, offset);
offset += 2;
if (tag.equals(TIME_ATTR_TAG)) {
readTimeAttr(data, offset, len - offset);
break;
}
final ZipShort size = new ZipShort(data, offset);
offset += 2 + size.getValue();
}
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Reads the stream until it find the "End of central directory
* record" and consumes it as well.
*/
private void skipRemainderOfArchive() throws IOException {
// skip over central directory. One LFH has been read too much
// already. The calculation discounts file names and extra
// data so it will be too short.
realSkip((long) entriesRead * CFH_LEN - LFH_LEN);
findEocdRecord();
realSkip((long) ZipFile.MIN_EOCD_SIZE - WORD /* signature */ - SHORT /* comment len */);
readFully(shortBuf);
// file comment
realSkip(ZipShort.getValue(shortBuf));
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Parses the supported flags from the given archive data.
*
* @param data local file header or a central directory entry.
* @param offset offset at which the general purpose bit starts
* @return parsed flags
*/
public static GeneralPurposeBit parse(final byte[] data, final int offset) {
final int generalPurposeFlag = ZipShort.getValue(data, offset);
final GeneralPurposeBit b = new GeneralPurposeBit();
b.useDataDescriptor((generalPurposeFlag & DATA_DESCRIPTOR_FLAG) != 0);
b.useUTF8ForNames((generalPurposeFlag & UFT8_NAMES_FLAG) != 0);
b.useStrongEncryption((generalPurposeFlag & STRONG_ENCRYPTION_FLAG) != 0);
b.useEncryption((generalPurposeFlag & ENCRYPTION_FLAG) != 0);
b.slidingDictionarySize = (generalPurposeFlag & SLIDING_DICTIONARY_SIZE_FLAG) != 0 ? 8192 : 4096;
b.numberOfShannonFanoTrees = (generalPurposeFlag & NUMBER_OF_SHANNON_FANO_TREES_FLAG) != 0 ? 3 : 2;
return b;
}
内容来源于网络,如有侵权,请联系作者删除!