本文整理了Java中org.apache.commons.compress.archivers.zip.ZipShort
类的一些代码示例,展示了ZipShort
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipShort
类的具体详情如下:
包路径:org.apache.commons.compress.archivers.zip.ZipShort
类名称:ZipShort
[英]Utility class that represents a two byte integer with conversion rules for the little endian byte order of ZIP files.
[中]一个实用程序类,它表示一个两字节的整数,并带有ZIP文件小端字节顺序的转换规则。
代码示例来源:origin: org.apache.commons/commons-compress
@Override
public ZipShort getCentralDirectoryLength() {
return new ZipShort((size != null ? DWORD : 0)
+ (compressedSize != null ? DWORD : 0)
+ (relativeHeaderOffset != null ? DWORD : 0)
+ (diskStart != null ? WORD : 0));
}
代码示例来源: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
/**
* 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
private void readTimeAttr(final byte[] data, int offset, final int length) {
if (length >= 2 + 3 * 8) {
final ZipShort tagValueLength = new ZipShort(data, offset);
if (TIME_ATTR_SIZE.equals(tagValueLength)) {
offset += 2;
modifyTime = new ZipEightByteInteger(data, offset);
offset += 8;
accessTime = new ZipEightByteInteger(data, offset);
offset += 8;
createTime = new ZipEightByteInteger(data, offset);
}
}
}
代码示例来源: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
LOOP:
while (start <= data.length - WORD) {
final ZipShort headerId = new ZipShort(data, start);
final int length = new ZipShort(data, start + 2).getValue();
if (start + WORD + length > data.length) {
switch(onUnparseableData.getKey()) {
+ Integer.toHexString(headerId.getValue())).initCause(aiobe);
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Get value as two bytes in big endian byte order.
* @param value the Java int to convert to bytes
* @return the converted int as a byte array in big endian byte order
*/
public static byte[] getBytes(final int value) {
final byte[] result = new byte[2];
putShort(value, result, 0);
return result;
}
代码示例来源:origin: org.apache.commons/commons-compress
@Override
public byte[] getCentralDirectoryData() {
return ZipShort.getBytes(alignment | (allowMethodChange ? ALLOW_METHOD_MESSAGE_CHANGE_FLAG : 0));
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Looks up an extra field by its header id.
*
* @param type the header id
* @return null if no such field exists.
*/
public ZipExtraField getExtraField(final ZipShort type) {
if (extraFields != null) {
for (final ZipExtraField extraField : extraFields) {
if (type.equals(extraField.getHeaderId())) {
return extraField;
}
}
}
return null;
}
代码示例来源: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: com.impetus.fabric/fabric-jdbc-driver-shaded
private void readTimeAttr(final byte[] data, int offset, final int length) {
if (length >= 2 + 3 * 8) {
final ZipShort tagValueLength = new ZipShort(data, offset);
if (TIME_ATTR_SIZE.equals(tagValueLength)) {
offset += 2;
modifyTime = new ZipEightByteInteger(data, offset);
offset += 8;
accessTime = new ZipEightByteInteger(data, offset);
offset += 8;
createTime = new ZipEightByteInteger(data, offset);
}
}
}
代码示例来源:origin: org.apache.commons/commons-compress
@Override
public byte[] getLocalFileDataData() {
byte[] content = new byte[BASE_SIZE + padding];
ZipShort.putShort(alignment | (allowMethodChange ? ALLOW_METHOD_MESSAGE_CHANGE_FLAG : 0),
content, 0);
return content;
}
代码示例来源:origin: org.apache.commons/commons-compress
final byte[] num = ZipShort.getBytes(Math.min(numberOfEntries,
ZIP64_MAGIC_SHORT));
writeCounted(num);
writeCounted(ZipShort.getBytes(dataLen));
streamCompressor.writeCounted(data.array(), data.arrayOffset(), dataLen);
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Remove an extra field.
* @param type the type of extra field to remove
*/
public void removeExtraField(final ZipShort type) {
if (extraFields == null) {
throw new java.util.NoSuchElementException();
}
final List<ZipExtraField> newResult = new ArrayList<>();
for (final ZipExtraField extraField : extraFields) {
if (!type.equals(extraField.getHeaderId())){
newResult.add( extraField);
}
}
if (extraFields.length == newResult.size()) {
throw new java.util.NoSuchElementException();
}
extraFields = newResult.toArray(new ZipExtraField[newResult.size()]);
setExtra();
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Length of the complete extra field in the local file data.
*
* @return The LocalFileDataLength value
*/
@Override
public ZipShort getLocalFileDataLength() {
return new ZipShort(localFileData == null ? 0 : localFileData.length);
}
代码示例来源: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
/**
* 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: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* 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
/**
* Encodes the set bits in a form suitable for ZIP archives.
*
* @param buf the output buffer
* @param offset
* The offset within the output buffer of the first byte to be written.
* must be non-negative and no larger than <tt>buf.length-2</tt>
*/
public void encode(final byte[] buf, final int offset) {
ZipShort.putShort((dataDescriptorFlag ? DATA_DESCRIPTOR_FLAG : 0)
|
(languageEncodingFlag ? UFT8_NAMES_FLAG : 0)
|
(encryptionFlag ? ENCRYPTION_FLAG : 0)
|
(strongEncryptionFlag ? STRONG_ENCRYPTION_FLAG : 0)
, buf, offset);
}
代码示例来源:origin: org.apache.commons/commons-compress
writeOut(ZipShort.getBytes(ZIP64_MIN_VERSION));
writeOut(ZipShort.getBytes(ZIP64_MIN_VERSION));
内容来源于网络,如有侵权,请联系作者删除!