本文整理汇总了Java中java.io.ByteArrayInputStream.available方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayInputStream.available方法的具体用法?Java ByteArrayInputStream.available怎么用?Java ByteArrayInputStream.available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.ByteArrayInputStream
的用法示例。
在下文中一共展示了ByteArrayInputStream.available方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BlobToString
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
private String BlobToString(Blob blob) throws SQLException, IOException {
String reString = "";
InputStream is = blob.getBinaryStream();
ByteArrayInputStream bais = (ByteArrayInputStream)is;
byte[] byte_data = new byte[bais.available()]; //bais.available()���ش����������ֽ���
bais.read(byte_data, 0,byte_data.length);//���������е����ݶ���ָ��������
reString = new String(byte_data,"utf-8"); //��תΪString����ʹ��ָ���ı��뷽ʽ
is.close();
return reString;
}
示例2: decrypt
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
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;
}
示例3: tlvParse
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Override
public TlvObject tlvParse(String data) {
//输入流转换
ByteArrayInputStream bais = new ByteArrayInputStream(EncodeUtil.bcd(data));
//解析结果
LinkedHashMap<String, TlvValue> values = new LinkedHashMap<String, TlvValue>();
//构建结果对象
TlvObject tlvObject = new Field55TlvObject(values);
try{
do{
//依次解析
Field55TlvValue tlvValue = read(bais);
//放置结果
values.put(tlvValue.getTagName(), tlvValue);
}while(bais.available() > 0);
}catch(IOException e){
e.printStackTrace();
}
return tlvObject;
}
示例4: read
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
private void read () throws IOException
{
int i;
int offset = 0;
final byte[] buffer = new byte[this.bufferSize];
while ( ( i = this.stream.read ( buffer, offset, buffer.length - offset ) ) > 0 )
{
logger.debug ( String.format ( "Read %s bytes", i ) );
final ByteArrayInputStream inputStream = new ByteArrayInputStream ( buffer, 0, i );
handleNewInput ( new InputStreamReader ( inputStream ) );
logger.debug ( String.format ( "%s byte(s) remaining", inputStream.available () ) );
offset = inputStream.available ();
if ( buffer.length - offset <= 0 )
{
throw new RuntimeException ( "Buffer is full" );
}
}
}
示例5: decrypt
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
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;
}
示例6: available
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Override
public int available() throws IOException {
if (message != null) {
try {
partial = new ByteArrayInputStream(serializer.serialize(message));
message = null;
return partial.available();
} catch (TException e) {
throw Status.INTERNAL.withDescription("failed to serialize thrift message")
.withCause(e).asRuntimeException();
}
} else if (partial != null) {
return partial.available();
}
return 0;
}
示例7: testDecoderKeepsAbstinence
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
private static void testDecoderKeepsAbstinence(Base64.Decoder dec)
throws Throwable {
List<Integer> vals = Arrays.asList(Integer.MIN_VALUE,
Integer.MIN_VALUE + 1, -1111, -2, -1, 0, 1, 2, 3, 1111,
Integer.MAX_VALUE - 1, Integer.MAX_VALUE,
rnd.nextInt(), rnd.nextInt(), rnd.nextInt(),
rnd.nextInt());
byte[] buf = new byte[3];
for (int off : vals) {
for (int len : vals) {
if (off >= 0 && len >= 0 && off <= buf.length - len) {
// valid args, skip them
continue;
}
// invalid args, test them
System.out.println("testing off=" + off + ", len=" + len);
String input = "AAAAAAAAAAAAAAAAAAAAAA";
ByteArrayInputStream bais =
new ByteArrayInputStream(input.getBytes("Latin1"));
try (InputStream is = dec.wrap(bais)) {
is.read(buf, off, len);
throw new RuntimeException("Expected IOOBEx was not thrown");
} catch (IndexOutOfBoundsException expected) {
}
if (bais.available() != input.length())
throw new RuntimeException("No input should be consumed, "
+ "but consumed " + (input.length() - bais.available())
+ " bytes");
}
}
}
示例8: decrypt
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
* Decrypt the given entry.
*
* @param entry
* {@link MutableEntry} to encrypt.
* @param result
* {@link MutableEntry} to write result to.
* @param columnVisibility
* The parsed column visibility.
*
* @throws IOException
* Not actually thrown.
*/
void decrypt(MutableEntry entry, MutableEntry result, ColumnVisibility columnVisibility) throws IOException {
ByteArrayInputStream ciphertextStream = new ByteArrayInputStream(entry.getBytes(config.destination));
DataInput ciphertextIn = new DataInputStream(ciphertextStream);
byte[] key = getKey(columnVisibility, ciphertextIn);
byte[] ciphertext = new byte[ciphertextStream.available()];
ciphertextIn.readFully(ciphertext);
byte[] decryptedData = encryptor.decrypt(key, ciphertext);
// Break apart the decrypted data.
ByteArrayInputStream dataStream = new ByteArrayInputStream(decryptedData);
DataInput dataIn = new DataInputStream(dataStream);
for (EntryField source : config.sources) {
switch (source) {
case ROW:
case COLUMN_FAMILY:
case COLUMN_QUALIFIER:
case COLUMN_VISIBILITY:
case VALUE:
int length = WritableUtils.readVInt(dataIn);
byte[] bytes = new byte[length];
dataIn.readFully(bytes);
result.setBytes(source, bytes);
break;
// case TIMESTAMP:
// result.timestamp = WritableUtils.readVLong(dataIn);
// break;
// case DELETE:
// result.delete = dataIn.readBoolean();
// break;
default:
throw new UnsupportedOperationException();
}
}
}
示例9: readExtensions
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
protected static Hashtable readExtensions(ByteArrayInputStream input)
throws IOException
{
if (input.available() < 1)
{
return null;
}
byte[] extBytes = TlsUtils.readOpaque16(input);
assertEmpty(input);
ByteArrayInputStream buf = new ByteArrayInputStream(extBytes);
// Integer -> byte[]
Hashtable extensions = new Hashtable();
while (buf.available() > 0)
{
Integer extType = Integers.valueOf(TlsUtils.readUint16(buf));
byte[] extValue = TlsUtils.readOpaque16(buf);
/*
* RFC 3546 2.3 There MUST NOT be more than one extension of the same type.
*/
if (null != extensions.put(extType, extValue))
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
}
return extensions;
}
示例10: getArrayOfIntValues
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
* Returns array of int values.
*/
public int[] getArrayOfIntValues() {
byte[] bufArray = (byte[])myValue;
if (bufArray != null) {
//ArrayList valList = new ArrayList();
ByteArrayInputStream bufStream =
new ByteArrayInputStream(bufArray);
int available = bufStream.available();
// total number of values is at the end of the stream
bufStream.mark(available);
bufStream.skip(available-1);
int length = bufStream.read();
bufStream.reset();
int[] valueArray = new int[length];
for (int i = 0; i < length; i++) {
// read length
int valLength = bufStream.read();
if (valLength != 4) {
// invalid data
return null;
}
byte[] bufBytes = new byte[valLength];
bufStream.read(bufBytes, 0, valLength);
valueArray[i] = convertToInt(bufBytes);
}
return valueArray;
}
return null;
}
示例11: getBody
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
* Returns the raw POST or PUT body to be sent.
*
* <p>By default, the body consists of the request parameters in
* application/x-www-form-urlencoded format. When overriding this method, consider overriding
* {@link #getBodyContentType()} as well to match the new body format.
*
* @throws AuthFailureError in the event of auth failure
*/
@Override
public byte[] getBody() throws AuthFailureError {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
try {
ByteArrayInputStream fileInputStream = new ByteArrayInputStream(getPartData().getContent());
int bytesAvailable = fileInputStream.available();
int maxBufferSize = 1024 * 1024;
int bufferSize = Math.min(bytesAvailable, maxBufferSize);
byte[] buffer = new byte[bufferSize];
int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
return bos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例12: testDecoderKeepsAbstinence
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
private static void testDecoderKeepsAbstinence(Base64.Decoder dec)
throws Throwable {
List<Integer> vals = new ArrayList<>(List.of(Integer.MIN_VALUE,
Integer.MIN_VALUE + 1, -1111, -2, -1, 0, 1, 2, 3, 1111,
Integer.MAX_VALUE - 1, Integer.MAX_VALUE));
vals.addAll(List.of(rnd.nextInt(), rnd.nextInt(), rnd.nextInt(),
rnd.nextInt()));
byte[] buf = new byte[3];
for (int off : vals) {
for (int len : vals) {
if (off >= 0 && len >= 0 && off <= buf.length - len) {
// valid args, skip them
continue;
}
// invalid args, test them
System.out.println("testing off=" + off + ", len=" + len);
String input = "AAAAAAAAAAAAAAAAAAAAAA";
ByteArrayInputStream bais =
new ByteArrayInputStream(input.getBytes("Latin1"));
try (InputStream is = dec.wrap(bais)) {
is.read(buf, off, len);
throw new RuntimeException("Expected IOOBEx was not thrown");
} catch (IndexOutOfBoundsException expected) {
}
if (bais.available() != input.length())
throw new RuntimeException("No input should be consumed, "
+ "but consumed " + (input.length() - bais.available())
+ " bytes");
}
}
}
示例13: getArrayOfStringValues
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
* Returns array of String values.
*/
public String[] getArrayOfStringValues() {
byte[] bufArray = (byte[])myValue;
if (bufArray != null) {
ByteArrayInputStream bufStream =
new ByteArrayInputStream(bufArray);
int available = bufStream.available();
// total number of values is at the end of the stream
bufStream.mark(available);
bufStream.skip(available-1);
int length = bufStream.read();
bufStream.reset();
String[] valueArray = new String[length];
for (int i = 0; i < length; i++) {
// read length
int valLength = bufStream.read();
byte[] bufBytes = new byte[valLength];
bufStream.read(bufBytes, 0, valLength);
try {
valueArray[i] = new String(bufBytes, "UTF-8");
} catch (java.io.UnsupportedEncodingException uee) {
}
}
return valueArray;
}
return null;
}
示例14: SmsStatusReportTpduImpl
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public SmsStatusReportTpduImpl(byte[] data, Charset gsm8Charset) throws MAPException {
this();
if (data == null)
throw new MAPException("Error creating a new SmsStatusReport instance: data is empty");
if (data.length < 1)
throw new MAPException("Error creating a new SmsStatusReport instance: data length is equal zero");
ByteArrayInputStream stm = new ByteArrayInputStream(data);
int bt = stm.read();
if ((bt & _MASK_TP_UDHI) != 0)
this.userDataHeaderIndicator = true;
if ((bt & _MASK_TP_MMS) == 0)
this.moreMessagesToSend = true;
if ((bt & _MASK_TP_LP) != 0)
this.forwardedOrSpawned = true;
int code = (bt & _MASK_TP_SRQ) >> 5;
this.statusReportQualifier = StatusReportQualifier.getInstance(code);
this.messageReference = stm.read();
if (this.messageReference == -1)
throw new MAPException("Error creating a new SmsStatusReport instance: messageReference field has not been found");
this.recipientAddress = AddressFieldImpl.createMessage(stm);
this.serviceCentreTimeStamp = AbsoluteTimeStampImpl.createMessage(stm);
this.dischargeTime = AbsoluteTimeStampImpl.createMessage(stm);
bt = stm.read();
if (bt == -1)
throw new MAPException("Error creating a new SmsStatusReport instance: Status field has not been found");
this.status = new StatusImpl(bt);
bt = stm.read();
if (bt == -1)
this.parameterIndicator = new ParameterIndicatorImpl(0);
else
this.parameterIndicator = new ParameterIndicatorImpl(bt);
if (this.parameterIndicator.getTP_PIDPresence()) {
bt = stm.read();
if (bt == -1)
throw new MAPException(
"Error creating a new SmsStatusReport instance: protocolIdentifier field has not been found");
this.protocolIdentifier = new ProtocolIdentifierImpl(bt);
}
if (this.parameterIndicator.getTP_DCSPresence()) {
bt = stm.read();
if (bt == -1)
throw new MAPException(
"Error creating a new SmsStatusReport instance: dataCodingScheme field has not been found");
this.dataCodingScheme = new DataCodingSchemeImpl(bt);
}
if (this.parameterIndicator.getTP_UDLPresence()) {
this.userDataLength = stm.read();
if (this.userDataLength == -1)
throw new MAPException("Error creating a new SmsStatusReport instance: userDataLength field has not been found");
int avail = stm.available();
byte[] buf = new byte[avail];
try {
stm.read(buf);
} catch (IOException e) {
throw new MAPException("IOException while creating a new SmsStatusReport instance: " + e.getMessage(), e);
}
userData = new UserDataImpl(buf, dataCodingScheme, userDataLength, userDataHeaderIndicator, gsm8Charset);
}
}
示例15: SmsDeliverReportTpduImpl
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public SmsDeliverReportTpduImpl(byte[] data, Charset gsm8Charset) throws MAPException {
this();
if (data == null)
throw new MAPException("Error creating a new SmsDeliverReportTpdu instance: data is empty");
if (data.length < 1)
throw new MAPException("Error creating a new SmsDeliverReportTpdu instance: data length is equal zero");
ByteArrayInputStream stm = new ByteArrayInputStream(data);
int bt = stm.read();
if ((bt & _MASK_TP_UDHI) != 0)
this.userDataHeaderIndicator = true;
bt = stm.read();
if (bt == -1)
throw new MAPException(
"Error creating a new SmsDeliverReportTpdu instance: Failure-Cause and Parameter-Indicator fields have not been found");
if ((bt & 0x80) != 0) {
// Failure-Cause exists
this.failureCause = new FailureCauseImpl(bt);
bt = stm.read();
if (bt == -1)
throw new MAPException(
"Error creating a new SmsDeliverReportTpdu instance: Parameter-Indicator field has not been found");
}
this.parameterIndicator = new ParameterIndicatorImpl(bt);
if (this.parameterIndicator.getTP_PIDPresence()) {
bt = stm.read();
if (bt == -1)
throw new MAPException(
"Error creating a new SmsDeliverTpduImpl instance: protocolIdentifier field has not been found");
this.protocolIdentifier = new ProtocolIdentifierImpl(bt);
}
if (this.parameterIndicator.getTP_DCSPresence()) {
bt = stm.read();
if (bt == -1)
throw new MAPException(
"Error creating a new SmsDeliverTpduImpl instance: dataCodingScheme field has not been found");
this.dataCodingScheme = new DataCodingSchemeImpl(bt);
}
if (this.parameterIndicator.getTP_UDLPresence()) {
this.userDataLength = stm.read();
if (this.userDataLength == -1)
throw new MAPException(
"Error creating a new SmsDeliverTpduImpl instance: userDataLength field has not been found");
int avail = stm.available();
byte[] buf = new byte[avail];
try {
stm.read(buf);
} catch (IOException e) {
throw new MAPException("IOException while creating a new SmsDeliverTpduImpl instance: " + e.getMessage(), e);
}
userData = new UserDataImpl(buf, dataCodingScheme, userDataLength, userDataHeaderIndicator, gsm8Charset);
}
}