本文整理了Java中java.io.ByteArrayInputStream.available()
方法的一些代码示例,展示了ByteArrayInputStream.available()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayInputStream.available()
方法的具体详情如下:
包路径:java.io.ByteArrayInputStream
类名称:ByteArrayInputStream
方法名:available
[英]Returns the number of remaining bytes.
[中]返回剩余字节数。
代码示例来源:origin: stackoverflow.com
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());
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* 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);
}
代码示例来源:origin: rest-assured/rest-assured
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) {
代码示例来源:origin: ethereum/ethereumj
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;
}
代码示例来源:origin: hierynomus/sshj
@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*/)) {
代码示例来源:origin: bumptech/glide
@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());
}
代码示例来源:origin: jenkinsci/jenkins
ByteArrayInputStream b = new ByteArrayInputStream(in, next, rest);
int bytesUsed = rest - b.available(); // bytes consumed by annotations
written += bytesUsed;
代码示例来源:origin: prestodb/presto
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();
}
}
代码示例来源:origin: bumptech/glide
@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());
}
代码示例来源:origin: bumptech/glide
@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());
}
}
代码示例来源:origin: ethereum/ethereumj
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;
}
代码示例来源:origin: apache/flink
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);
}
代码示例来源:origin: apache/flink
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);
代码示例来源:origin: stackoverflow.com
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());
代码示例来源:origin: commons-io/commons-io
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) {
代码示例来源:origin: ethereum/ethereumj
ByteArrayInputStream bIn = new ByteArrayInputStream(in, inOff, inLen);
int encLength = (inLen - bIn.available());
this.V = Arrays.copyOfRange(in, inOff, inOff + encLength);
代码示例来源:origin: apache/zookeeper
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()) {
代码示例来源:origin: org.apache.zookeeper/zookeeper
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()) {
代码示例来源:origin: devnied/EMV-NFC-Paycard-Enrollment
/**
* 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;
}
代码示例来源:origin: devnied/EMV-NFC-Paycard-Enrollment
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();
}
内容来源于网络,如有侵权,请联系作者删除!