本文整理了Java中java.io.ByteArrayInputStream.read()
方法的一些代码示例,展示了ByteArrayInputStream.read()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayInputStream.read()
方法的具体详情如下:
包路径:java.io.ByteArrayInputStream
类名称:ByteArrayInputStream
方法名:read
[英]Reads a single byte from the source byte array and returns it as an integer in the range from 0 to 255. Returns -1 if the end of the source array has been reached.
[中]从源字节数组读取单个字节,并将其作为0到255范围内的整数返回。如果已到达源数组的结尾,则返回-1。
代码示例来源:origin: CarGuo/GSYVideoPlayer
@Override
public int read(byte[] buffer, long offset, int length) throws ProxyCacheException {
if (offset >= data.length) {
return -1;
}
if (offset > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Too long offset for memory cache " + offset);
}
return new ByteArrayInputStream(data).read(buffer, (int) offset, length);
}
代码示例来源:origin: scouter-project/scouter
public void toObject(byte[] bytes) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
int len = in.read();
byte[] idBytes = new byte[len];
in.read(idBytes);
this.id = new String(idBytes);
len = in.read();
byte[] passBytes = new byte[len];
in.read(passBytes);
this.password = new String(passBytes);
len = in.read();
byte[] emailBytes = new byte[len];
in.read(emailBytes);
this.email = new String(emailBytes);
len = in.read();
byte[] groupBytes = new byte[len];
in.read(groupBytes);
this.group = new String(groupBytes);
in.close();
}
代码示例来源:origin: scouter-project/scouter
public void toObject(byte[] bytes) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
int len = in.read();
byte[] idBytes = new byte[len];
in.read(idBytes);
this.id = new String(idBytes);
len = in.read();
byte[] passBytes = new byte[len];
in.read(passBytes);
this.password = new String(passBytes);
len = in.read();
byte[] emailBytes = new byte[len];
in.read(emailBytes);
this.email = new String(emailBytes);
len = in.read();
byte[] groupBytes = new byte[len];
in.read(groupBytes);
this.group = new String(groupBytes);
in.close();
}
代码示例来源:origin: scouter-project/scouter
public void toObject(byte[] bytes) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
int len = in.read();
byte[] idBytes = new byte[len];
in.read(idBytes);
this.id = new String(idBytes);
len = in.read();
byte[] passBytes = new byte[len];
in.read(passBytes);
this.password = new String(passBytes);
len = in.read();
byte[] emailBytes = new byte[len];
in.read(emailBytes);
this.email = new String(emailBytes);
len = in.read();
byte[] groupBytes = new byte[len];
in.read(groupBytes);
this.group = new String(groupBytes);
in.close();
}
代码示例来源:origin: scouter-project/scouter
public void toObject(byte[] bytes) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
int len = in.read();
byte[] idBytes = new byte[len];
in.read(idBytes);
this.id = new String(idBytes);
len = in.read();
byte[] passBytes = new byte[len];
in.read(passBytes);
this.password = new String(passBytes);
len = in.read();
byte[] emailBytes = new byte[len];
in.read(emailBytes);
this.email = new String(emailBytes);
len = in.read();
byte[] groupBytes = new byte[len];
in.read(groupBytes);
this.group = new String(groupBytes);
in.close();
}
代码示例来源:origin: scouter-project/scouter
public void toObject(byte[] bytes) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
int len = in.read();
byte[] idBytes = new byte[len];
in.read(idBytes);
this.id = new String(idBytes);
len = in.read();
byte[] passBytes = new byte[len];
in.read(passBytes);
this.password = new String(passBytes);
len = in.read();
byte[] emailBytes = new byte[len];
in.read(emailBytes);
this.email = new String(emailBytes);
len = in.read();
byte[] groupBytes = new byte[len];
in.read(groupBytes);
this.group = new String(groupBytes);
in.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
byte[] bytes = (byte[]) invocation.getArguments()[0];
ByteArrayInputStream inputStream = new ByteArrayInputStream(TEXT.getBytes());
return inputStream.read(bytes);
}
});
代码示例来源:origin: apache/nifi
private EncryptionMetadata extractEncryptionMetadata(byte[] encryptedRecord) throws EncryptionException, IOException, ClassNotFoundException {
if (encryptedRecord == null || encryptedRecord.length < MIN_METADATA_LENGTH) {
throw new EncryptionException("The encrypted record is too short to contain the metadata");
}
// Skip the first byte (SENTINEL) and don't need to copy all the serialized record
ByteArrayInputStream bais = new ByteArrayInputStream(encryptedRecord);
bais.read();
try (ObjectInputStream ois = new ObjectInputStream(bais)) {
return (EncryptionMetadata) ois.readObject();
}
}
代码示例来源: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: cloudfoundry/uaa
public byte[] decrypt(byte[] encrypt) throws EncryptionServiceException {
try {
byte[] myNonce = new byte[GCM_IV_NONCE_SIZE_BYTES];
byte[] mySalt = new byte[PBKDF2_SALT_SIZE_BYTES];
ByteArrayInputStream fileInputStream = new ByteArrayInputStream(encrypt);
fileInputStream.read(myNonce);
fileInputStream.read(mySalt);
SecretKey key = new SecretKeySpec(generateKey(mySalt), CIPHER);
Cipher myCipher = Cipher.getInstance(CIPHERSCHEME);
GCMParameterSpec spec = new GCMParameterSpec(GCM_AUTHENTICATION_TAG_SIZE_BITS, myNonce);
myCipher.init(Cipher.DECRYPT_MODE, key, spec);
return myCipher.doFinal(Arrays.copyOfRange(encrypt, GCM_IV_NONCE_SIZE_BYTES + PBKDF2_SALT_SIZE_BYTES, encrypt.length));
} catch (Exception e) {
logger.error("Decryption failed", e);
throw new EncryptionServiceException(e);
}
}
代码示例来源:origin: jersey/jersey
@Override
public int read() throws IOException {
if (byteArrayInputStream == null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream stream = null;
try {
try {
stream = requestContext.getWorkers().writeTo(
entity, entity.getClass(), null, null, response.getMediaType(),
response.getMetadata(), requestContext.getPropertiesDelegate(), baos,
Collections.<WriterInterceptor>emptyList());
} finally {
if (stream != null) {
stream.close();
}
}
} catch (IOException e) {
// ignore
}
byteArrayInputStream = new ByteArrayInputStream(baos.toByteArray());
}
return byteArrayInputStream.read();
}
};
代码示例来源:origin: stackoverflow.com
input = new ByteArrayInputStream(cachedBytes.toByteArray());
return input.read();
代码示例来源:origin: jersey/jersey
@Override
public int read() throws IOException {
if (byteArrayInputStream == null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream stream = null;
try {
try {
stream = requestContext.getWorkers().writeTo(
entity, entity.getClass(), null, null, response.getMediaType(),
response.getMetadata(), requestContext.getPropertiesDelegate(), baos,
Collections.<WriterInterceptor>emptyList());
} finally {
if (stream != null) {
stream.close();
}
}
} catch (IOException e) {
// ignore
}
byteArrayInputStream = new ByteArrayInputStream(baos.toByteArray());
}
return byteArrayInputStream.read();
}
};
代码示例来源:origin: igniterealtime/Openfire
try (ByteArrayInputStream in = new ByteArrayInputStream(content)) {
try (OutputStream out = response.getOutputStream()) {
while ((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void getInputStreamReadBytePromotion() throws Exception {
byte[] bytes = new byte[] { -1 };
this.os.write(bytes);
InputStream inputStream = this.os.getInputStream();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
assertEquals(bais.read(), inputStream.read());
}
代码示例来源:origin: hierynomus/sshj
pending = new ByteArrayInputStream(buf, 0, recvLen);
} else if (!retrieveUnconfirmedRead(true /*blocking*/)) {
return pending.read(into, off, len);
代码示例来源:origin: org.glassfish.jersey.core/jersey-client
@Override
public int read() throws IOException {
if (byteArrayInputStream == null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream stream = null;
try {
try {
stream = requestContext.getWorkers().writeTo(
entity, entity.getClass(), null, null, response.getMediaType(),
response.getMetadata(), requestContext.getPropertiesDelegate(), baos,
Collections.<WriterInterceptor>emptyList());
} finally {
if (stream != null) {
stream.close();
}
}
} catch (IOException e) {
// ignore
}
byteArrayInputStream = new ByteArrayInputStream(baos.toByteArray());
}
return byteArrayInputStream.read();
}
};
代码示例来源: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: plantuml/plantuml
final ByteArrayInputStream bais = new ByteArrayInputStream(resultB);
final int type = bais.read();
if (type == 0) {
final int version = bais.read();
final byte sha[] = readBytes(bais, 64);
final long now = readLong(bais);
final int version = bais.read();
final byte sha[] = readBytes(bais, 64);
final long now = readLong(bais);
代码示例来源:origin: Tencent/tinker
private byte[] adjustDebugInfoItemSTM(byte[] infoSTM) {
ByteArrayInputStream bais = new ByteArrayInputStream(infoSTM);
final ByteArrayInputStream baisRef = bais;
ByteInput inAdapter = new ByteInput() {
int opcode = bais.read() & 0xFF;
baos.write(opcode);
switch (opcode) {
内容来源于网络,如有侵权,请联系作者删除!