Refine search
import java.io.*; public class Test { public static void main(String[] arg) throws Throwable { File f = new File(arg[0]); InputStream in = new FileInputStream(f); byte[] buff = new byte[8000]; int bytesRead = 0; ByteArrayOutputStream bao = new ByteArrayOutputStream(); while((bytesRead = in.read(buff)) != -1) { bao.write(buff, 0, bytesRead); } byte[] data = bao.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(data); System.out.println(bin.available()); } }
/** * Called after we read the whole line of plain text. */ protected void eol(byte[] in, int sz) throws IOException { int next = ConsoleNote.findPreamble(in,0,sz); // perform byte[]->char[] while figuring out the char positions of the BLOBs int written = 0; while (next>=0) { if (next>written) { out.write(in,written,next-written); written = next; } else { assert next==written; } int rest = sz - next; ByteArrayInputStream b = new ByteArrayInputStream(in, next, rest); ConsoleNote.skip(new DataInputStream(b)); int bytesUsed = rest - b.available(); // bytes consumed by annotations written += bytesUsed; next = ConsoleNote.findPreamble(in,written,sz-written); } // finish the remaining bytes->chars conversion out.write(in,written,sz-written); }
entity = new InputStreamEntity(in, in.available()); } else if (data instanceof InputStream) { entity = new InputStreamEntity((InputStream) data, -1); } else if (data instanceof byte[]) { byte[] out = ((byte[]) data); entity = new InputStreamEntity(new ByteArrayInputStream( out), out.length); } else if (data instanceof ByteArrayOutputStream) { ByteArrayOutputStream out = ((ByteArrayOutputStream) data); entity = new InputStreamEntity(new ByteArrayInputStream( out.toByteArray()), out.size()); } else if (data instanceof Closure) {
public static byte[] decrypt(BigInteger privKey, byte[] cipher, byte[] macData) throws IOException, InvalidCipherTextException { byte[] plaintext; ByteArrayInputStream is = new ByteArrayInputStream(cipher); byte[] ephemBytes = new byte[2*((CURVE.getCurve().getFieldSize()+7)/8) + 1]; is.read(ephemBytes); ECPoint ephem = CURVE.getCurve().decodePoint(ephemBytes); byte[] IV = new byte[KEY_SIZE /8]; is.read(IV); byte[] cipherBody = new byte[is.available()]; is.read(cipherBody); plaintext = decrypt(ephem, privKey, IV, cipherBody, macData); return plaintext; }
@Override public int read(byte[] into, int off, int len) throws IOException { while (!eof && pending.available() <= 0) { pending = new ByteArrayInputStream(buf, 0, recvLen); } else if (!retrieveUnconfirmedRead(true /*blocking*/)) {
@Test public void testReturnsStreamAvailable_whenMarkIsSet_withMarkGreaterThanStreamAvailable() throws IOException { ByteArrayInputStream wrapped = new ByteArrayInputStream(new byte[MARK_LIMIT]); MarkEnforcingInputStream is = new MarkEnforcingInputStream(wrapped); is.mark(wrapped.available() + 1); assertEquals(wrapped.available(), is.available()); }
ByteArrayInputStream b = new ByteArrayInputStream(in, next, rest); int bytesUsed = rest - b.available(); // bytes consumed by annotations written += bytesUsed;
private static Optional<DictionaryPage> readDictionaryPage(byte[] data, CompressionCodecName codecName) { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(data); PageHeader pageHeader = Util.readPageHeader(inputStream); if (pageHeader.type != PageType.DICTIONARY_PAGE) { return Optional.empty(); } Slice compressedData = wrappedBuffer(data, data.length - inputStream.available(), pageHeader.getCompressed_page_size()); DictionaryPageHeader dicHeader = pageHeader.getDictionary_page_header(); ParquetEncoding encoding = getParquetEncoding(Encoding.valueOf(dicHeader.getEncoding().name())); int dictionarySize = dicHeader.getNum_values(); return Optional.of(new DictionaryPage(decompress(codecName, compressedData, pageHeader.getUncompressed_page_size()), dictionarySize, encoding)); } catch (IOException ignored) { return Optional.empty(); } }
@Test public void testReturnsStreamAvailable_whenMarkIsNotSet() throws IOException { ByteArrayInputStream wrapped = new ByteArrayInputStream(new byte[MARK_LIMIT]); MarkEnforcingInputStream is = new MarkEnforcingInputStream(wrapped); assertEquals(wrapped.available(), is.available()); }
@Test public void testReturnsMarkLimitAsAvailable_whenMarkIsSet_withMarkLessThanStreamAvailable() throws IOException { ByteArrayInputStream wrapped = new ByteArrayInputStream(new byte[MARK_LIMIT]); MarkEnforcingInputStream is = new MarkEnforcingInputStream(wrapped); int expected = wrapped.available() - 1; is.mark(expected); assertEquals(expected, is.available()); } }
public static byte[] decrypt(BigInteger prv, byte[] cipher) throws InvalidCipherTextException, IOException { ByteArrayInputStream is = new ByteArrayInputStream(cipher); byte[] ephemBytes = new byte[2*((curve.getCurve().getFieldSize()+7)/8) + 1]; is.read(ephemBytes); ECPoint ephem = curve.getCurve().decodePoint(ephemBytes); byte[] IV = new byte[KEY_SIZE /8]; is.read(IV); byte[] cipherBody = new byte[is.available()]; is.read(cipherBody); EthereumIESEngine iesEngine = makeIESEngine(false, ephem, prv, IV); byte[] message = iesEngine.processBlock(cipherBody, 0, cipherBody.length); return message; }
public static void testSerialization(String[] values) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); DataOutputViewStreamWrapper serializer = new DataOutputViewStreamWrapper(baos); for (String value : values) { StringValue sv = new StringValue(value); sv.write(serializer); } serializer.close(); baos.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DataInputViewStreamWrapper deserializer = new DataInputViewStreamWrapper(bais); int num = 0; while (bais.available() > 0) { StringValue deser = new StringValue(); deser.read(deserializer); assertEquals("DeserializedString differs from original string.", values[num], deser.getValue()); num++; } assertEquals("Wrong number of deserialized values", values.length, num); }
baos.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DataInputViewStreamWrapper source = new DataInputViewStreamWrapper(bais); ByteArrayInputStream validateInput = new ByteArrayInputStream(targetOutput.toByteArray()); DataInputViewStreamWrapper validate = new DataInputViewStreamWrapper(validateInput); while (validateInput.available() > 0) { sValue.read(validate);
byte[] bytes = {2, 6, -2, 1, 7}; IntStream is = IntStream.range(0, bytes.length).map(i -> bytes[i]); ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); IntStream is2 = IntStream.generate(inputStream::read).limit(inputStream.available());
public void testDataBytesCalled() throws Exception { final byte[] buffer = MessageDigestCalculatingInputStreamTest.generateRandomByteStream(4096); final ByteArrayInputStream bais = new ByteArrayInputStream(buffer); final ObservableInputStream ois = new ObservableInputStream(bais); final LastBytesKeepingObserver lko = new LastBytesKeepingObserver(); ois.add(lko); for (;;) { if (bais.available() >= 2048) { final int result = ois.read(readBuffer); if (result == -1) { final int res = Math.min(11, bais.available()); final int result = ois.read(readBuffer, 1, 11); if (result == -1) {
ByteArrayInputStream bIn = new ByteArrayInputStream(in, inOff, inLen); int encLength = (inLen - bIn.available()); this.V = Arrays.copyOfRange(in, inOff, inOff + encLength);
public static Record deserializeTxn(byte txnBytes[], TxnHeader hdr) throws IOException { final ByteArrayInputStream bais = new ByteArrayInputStream(txnBytes); InputArchive ia = BinaryInputArchive.getArchive(bais); bais.mark(bais.available()); Record txn = null; switch (hdr.getType()) {
public static Record deserializeTxn(byte txnBytes[], TxnHeader hdr) throws IOException { final ByteArrayInputStream bais = new ByteArrayInputStream(txnBytes); InputArchive ia = BinaryInputArchive.getArchive(bais); bais.mark(bais.available()); Record txn = null; switch (hdr.getType()) {
/** * Method used to parser Tag and length * * @param data * data to parse * @return list of tag and length */ public static List<TagAndLength> parseTagAndLength(final byte[] data) { List<TagAndLength> tagAndLengthList = new ArrayList<TagAndLength>(); if (data != null) { ByteArrayInputStream stream = new ByteArrayInputStream(data); while (stream.available() > 0) { if (stream.available() < 2) { throw new TlvException("Data length < 2 : " + stream.available()); } ITag tag = searchTagById(TlvUtil.readTagIdBytes(stream)); int tagValueLength = TlvUtil.readTagLength(stream); tagAndLengthList.add(new TagAndLength(tag, tagValueLength)); } } return tagAndLengthList; }
public static String getFormattedTagAndLength(final byte[] data, final int indentLength) { StringBuilder buf = new StringBuilder(); String indent = getSpaces(indentLength); ByteArrayInputStream stream = new ByteArrayInputStream(data); boolean firstLine = true; while (stream.available() > 0) { if (firstLine) { firstLine = false; } else { buf.append("\n"); } buf.append(indent); ITag tag = searchTagById(stream); int length = TlvUtil.readTagLength(stream); buf.append(prettyPrintHex(tag.getTagBytes())); buf.append(" "); buf.append(String.format("%02x", length)); buf.append(" -- "); buf.append(tag.getName()); } return buf.toString(); }