本文整理了Java中org.apache.poi.util.IOUtils.safelyAllocate()
方法的一些代码示例,展示了IOUtils.safelyAllocate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.safelyAllocate()
方法的具体详情如下:
包路径:org.apache.poi.util.IOUtils
类名称:IOUtils
方法名:safelyAllocate
暂无
代码示例来源:origin: org.apache.poi/poi
public ChunkedCipherInputStream(InputStream stream, long size, int chunkSize, int initialPos)
throws GeneralSecurityException {
super(stream);
this.size = size;
this.pos = initialPos;
this.chunkSize = chunkSize;
int cs = chunkSize == -1 ? 4096 : chunkSize;
this.chunk = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH);
this.plain = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH);
this.chunkBits = Integer.bitCount(chunk.length-1);
this.lastIndex = (int)(pos >> chunkBits);
this.cipher = initCipherForBlock(null, lastIndex);
}
代码示例来源:origin: org.apache.poi/poi
private static byte[] getBlockX(byte[] hash, int size, byte fill) {
if (hash.length == size) return hash;
byte[] result = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
Arrays.fill(result, fill);
System.arraycopy(hash, 0, result, 0, Math.min(result.length, hash.length));
return result;
}
代码示例来源:origin: org.apache.poi/poi
public UnknownSubRecord(LittleEndianInput in, int sid, int size) {
_sid = sid;
byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
in.readFully(buf);
_data = buf;
}
@Override
代码示例来源:origin: org.apache.poi/poi
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset );
// Save the data, ready for the calling code to do something
// useful with it
thedata = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining );
return bytesRemaining + 8;
}
代码示例来源:origin: org.apache.poi/poi
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset );
int pos = offset + 8;
remainingData = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy( data, pos, remainingData, 0, bytesRemaining );
return 8 + bytesRemaining;
}
代码示例来源:origin: org.apache.poi/poi
private static byte[] readRawData(LittleEndianInput in, int size) {
if (size < 0) {
throw new IllegalArgumentException("Negative size (" + size + ")");
}
if (size == 0) {
return EMPTY_BYTE_ARRAY;
}
byte[] result = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
in.readFully(result);
return result;
}
代码示例来源:origin: org.apache.poi/poi
public static String readCompressedUnicode(LittleEndianInput in, int nChars) {
byte[] buf = IOUtils.safelyAllocate(nChars, MAX_RECORD_LENGTH);
in.readFully(buf);
return new String(buf, ISO_8859_1);
}
代码示例来源:origin: org.apache.poi/poi
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesAfterHeader = readHeader( data, offset );
int pos = offset + HEADER_SIZE;
field_pictureData = IOUtils.safelyAllocate(bytesAfterHeader, MAX_RECORD_LENGTH);
System.arraycopy(data, pos, field_pictureData, 0, bytesAfterHeader);
return bytesAfterHeader + 8;
}
代码示例来源:origin: org.apache.poi/poi
private String readUnicodeString(RLEDecompressingInputStream in, int unicodeNameRecordLength) throws IOException {
byte[] buffer = IOUtils.safelyAllocate(unicodeNameRecordLength, MAX_STRING_LENGTH);
int bytesRead = IOUtils.readFully(in, buffer);
if (bytesRead != unicodeNameRecordLength) {
throw new EOFException();
}
return new String(buffer, StringUtil.UTF16LE);
}
代码示例来源:origin: org.apache.poi/poi
public GroupMarkerSubRecord(LittleEndianInput in, int size) {
byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
in.readFully(buf);
reserved = buf;
}
代码示例来源:origin: org.apache.poi/poi
public static void dump(POIFSFileSystem fs, int startBlock, String name, File parent) throws IOException {
File file = new File(parent, name);
try (FileOutputStream out = new FileOutputStream(file)) {
POIFSStream stream = new POIFSStream(fs, startBlock);
byte[] b = IOUtils.safelyAllocate(fs.getBigBlockSize(), MAX_RECORD_LENGTH);
for (ByteBuffer bb : stream) {
int len = bb.remaining();
bb.get(b);
out.write(b, 0, len);
}
}
}
}
代码示例来源:origin: org.apache.poi/poi
public ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize) throws IOException, GeneralSecurityException {
super(null);
this.chunkSize = chunkSize;
int cs = chunkSize == STREAMING ? 4096 : chunkSize;
this.chunk = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH);
this.plainByteFlags = new BitSet(cs);
this.chunkBits = Integer.bitCount(cs-1);
this.fileOut = TempFile.createTempFile("encrypted_package", "crypt");
this.fileOut.deleteOnExit();
this.out = new FileOutputStream(fileOut);
this.dir = dir;
this.cipher = initCipherForBlock(null, 0, false);
}
代码示例来源:origin: org.apache.poi/poi
public void read( LittleEndianInput lei ) {
int size = lei.readInt();
_value = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
if ( size > 0 ) {
lei.readFully(_value);
}
}
}
代码示例来源:origin: org.apache.poi/poi
public FtCblsSubRecord(LittleEndianInput in, int size) {
if (size != ENCODED_SIZE) {
throw new RecordFormatException("Unexpected size (" + size + ")");
}
//just grab the raw data
byte[] buf = IOUtils.safelyAllocate(size, ENCODED_SIZE);
in.readFully(buf);
reserved = buf;
}
代码示例来源:origin: org.apache.poi/poi
public byte[] getElement(int index) {
int actualSize = getActualSizeOfElements(getSizeOfElements());
byte[] result = IOUtils.safelyAllocate(actualSize, MAX_RECORD_LENGTH);
System.arraycopy(getComplexData(), FIXED_SIZE + index * actualSize, result, 0, result.length );
return result;
}
代码示例来源:origin: org.apache.poi/poi
private void setDefaults() {
futureHeader = new FtrHeader();
futureHeader.setRecordType(sid);
ext_formatting_length = 0;
ext_formatting_data = new byte[4];
formula_scale = Formula.create(Ptg.EMPTY_PTG_ARRAY);
ext_opts = 0;
priority = 0;
template_type = getConditionType();
template_param_length = 16;
template_params = IOUtils.safelyAllocate(template_param_length, MAX_RECORD_LENGTH);
}
代码示例来源:origin: org.apache.poi/poi
public void setNumberOfElementsInMemory(int numberOfElements) {
int expectedArraySize = numberOfElements * getActualSizeOfElements(getSizeOfElements()) + FIXED_SIZE;
if (expectedArraySize != getComplexData().length) {
byte[] newArray = IOUtils.safelyAllocate(expectedArraySize, MAX_RECORD_LENGTH);
System.arraycopy(getComplexData(), 0, newArray, 0, expectedArraySize);
setComplexData(newArray);
}
LittleEndian.putShort(getComplexData(), 2, (short) numberOfElements);
}
代码示例来源:origin: org.apache.poi/poi
public OldSheetRecord(RecordInputStream in) {
field_1_position_of_BOF = in.readInt();
field_2_visibility = in.readUByte();
field_3_type = in.readUByte();
int field_4_sheetname_length = in.readUByte();
field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, MAX_RECORD_LENGTH);
in.read(field_5_sheetname, 0, field_4_sheetname_length);
}
代码示例来源:origin: org.apache.poi/poi
public void setNumberOfElementsInArray(int numberOfElements) {
int expectedArraySize = numberOfElements * getActualSizeOfElements(getSizeOfElements()) + FIXED_SIZE;
if (expectedArraySize != getComplexData().length) {
byte[] newArray = IOUtils.safelyAllocate(expectedArraySize, MAX_RECORD_LENGTH);
System.arraycopy(getComplexData(), 0, newArray, 0, getComplexData().length);
setComplexData(newArray);
}
LittleEndian.putShort(getComplexData(), 0, (short) numberOfElements);
}
代码示例来源:origin: org.apache.poi/poi
public void setSizeOfElements(int sizeOfElements) {
LittleEndian.putShort( getComplexData(), 4, (short) sizeOfElements );
int expectedArraySize = getNumberOfElementsInArray() * getActualSizeOfElements(getSizeOfElements()) + FIXED_SIZE;
if (expectedArraySize != getComplexData().length) {
// Keep just the first 6 bytes. The rest is no good to us anyway.
byte[] newArray = IOUtils.safelyAllocate(expectedArraySize, MAX_RECORD_LENGTH);
System.arraycopy( getComplexData(), 0, newArray, 0, 6 );
setComplexData(newArray);
}
}
内容来源于网络,如有侵权,请联系作者删除!