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); }
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; }
public UnknownSubRecord(LittleEndianInput in, int sid, int size) { _sid = sid; byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); in.readFully(buf); _data = buf; } @Override
@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; }
@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; }
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; }
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); }
@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; }
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); }
public GroupMarkerSubRecord(LittleEndianInput in, int size) { byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); in.readFully(buf); reserved = buf; }
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); } } } }
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); }
public void read( LittleEndianInput lei ) { int size = lei.readInt(); _value = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); if ( size > 0 ) { lei.readFully(_value); } } }
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; }
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; }
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); }
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); }
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); }
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); }
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); } }