本文整理汇总了Java中java.io.ByteArrayInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayInputStream.read方法的具体用法?Java ByteArrayInputStream.read怎么用?Java ByteArrayInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.ByteArrayInputStream
的用法示例。
在下文中一共展示了ByteArrayInputStream.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Override
public int read() throws IOException {
if (message != null) {
try {
partial = new ByteArrayInputStream(serializer.serialize(message));
message = null;
} catch (TException e) {
throw Status.INTERNAL.withDescription("failed to serialize thrift message")
.withCause(e).asRuntimeException();
}
}
if (partial != null) {
return partial.read();
}
return -1;
}
示例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: getStringValue
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
* Returns String value.
*/
public String getStringValue() {
//assumes only 1 attribute value. Will get the first value
// if > 1.
String strVal = null;
byte[] bufArray = (byte[])myValue;
if (bufArray != null) {
ByteArrayInputStream bufStream =
new ByteArrayInputStream(bufArray);
int valLength = bufStream.read();
byte[] strBytes = new byte[valLength];
bufStream.read(strBytes, 0, valLength);
try {
strVal = new String(strBytes, "UTF-8");
} catch (java.io.UnsupportedEncodingException uee) {
}
}
return strVal;
}
示例4: buildDataPart
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
private void buildDataPart(DataOutputStream dataOutputStream, DataPart dataFile, String
inputName) throws IOException {
dataOutputStream.writeBytes("--" + this.boundary + "\r\n");
dataOutputStream.writeBytes("Content-Disposition: form-data; name=\"" + inputName + "\"; " +
"filename=\"" + dataFile.getFileName() + a.e + "\r\n");
if (!(dataFile.getType() == null || dataFile.getType().trim().isEmpty())) {
dataOutputStream.writeBytes("Content-Type: " + dataFile.getType() + "\r\n");
}
dataOutputStream.writeBytes("\r\n");
ByteArrayInputStream fileInputStream = new ByteArrayInputStream(dataFile.getContent());
int bufferSize = Math.min(fileInputStream.available(), 1048576);
byte[] buffer = new byte[bufferSize];
int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dataOutputStream.write(buffer, 0, bufferSize);
bufferSize = Math.min(fileInputStream.available(), 1048576);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
dataOutputStream.writeBytes("\r\n");
}
示例5: read
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public static Room read(ByteArrayInputStream bis) {
int roomId = bis.read();
int nameLength = bis.read();
byte[] roomName = new byte[nameLength];
bis.read(roomName, 0, nameLength);
// next three bytes are the rf address
int rfaddress = readRfAddress(bis);
return new Room(roomId, new String(roomName, UTF_8), rfaddress);
}
示例6: 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;
}
示例7: decrypt
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
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;
}
示例8: getInputStream
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Override
public ServletInputStream getInputStream() throws IOException {
//非json类型,直接返回
if (!super.getHeader(HttpHeaders.CONTENT_TYPE).equalsIgnoreCase(MediaType.APPLICATION_JSON_VALUE)) {
return super.getInputStream();
}
//为空,直接返回
String json = IOUtils.toString(super.getInputStream(), "utf-8");
if (StringUtils.isBlank(json)) {
return super.getInputStream();
}
//xss过滤
json = xssEncode(json);
final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8"));
return new ServletInputStream() {
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() throws IOException {
return bis.read();
}
};
}
示例9: getWapString
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
protected static byte[] getWapString(ByteArrayInputStream pduDataStream,
int stringType) {
assert(null != pduDataStream);
ByteArrayOutputStream out = new ByteArrayOutputStream();
int temp = pduDataStream.read();
assert(-1 != temp);
while((-1 != temp) && ('\0' != temp)) {
// check each of the character
if (stringType == TYPE_TOKEN_STRING) {
if (isTokenCharacter(temp)) {
out.write(temp);
}
} else {
if (isText(temp)) {
out.write(temp);
}
}
temp = pduDataStream.read();
assert(-1 != temp);
}
if (out.size() > 0) {
return out.toByteArray();
}
return null;
}
示例10: fromData
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public static BufferedImage fromData(byte[] data) {
System.out.println(data.length);
Validate.isTrue((data.length == 8192) || (data.length == 16384), "Skin data must be either 8192 or 16384 bytes long!");
int width = 64, height = (data.length == 16384) ? 64 : 32;
ByteArrayInputStream stream = new ByteArrayInputStream(data);
BufferedImage skin = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
Color color = new Color(stream.read(), stream.read(), stream.read(), stream.read());
skin.setRGB(x, y, color.getRGB());
}
}
return skin;
}
示例11: 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;
}
示例12: getInputStream
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Override
public ServletInputStream getInputStream() throws IOException {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
ServletInputStream servletInputStream = new ServletInputStream() {
public int read() throws IOException {
return byteArrayInputStream.read();
}
@Override
public boolean isFinished() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isReady() {
// TODO Auto-generated method stub
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
// TODO Auto-generated method stub
}
};
return servletInputStream;
}
示例13: 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);
}
}
示例14: SmsCommandTpduImpl
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public SmsCommandTpduImpl(byte[] data) throws MAPException {
this();
if (data == null)
throw new MAPException("Error creating a new SmsCommandTpdu instance: data is empty");
if (data.length < 1)
throw new MAPException("Error creating a new SmsCommandTpdu 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_SRR) != 0)
this.statusReportRequest = true;
this.messageReference = stm.read();
if (this.messageReference == -1)
throw new MAPException("Error creating a new SmsCommandTpdu instance: messageReference field has not been found");
bt = stm.read();
if (bt == -1)
throw new MAPException("Error creating a new SmsCommandTpdu instance: protocolIdentifier field has not been found");
this.protocolIdentifier = new ProtocolIdentifierImpl(bt);
bt = stm.read();
if (bt == -1)
throw new MAPException("Error creating a new SmsCommandTpdu instance: commandType field has not been found");
this.commandType = new CommandTypeImpl(bt);
this.messageNumber = stm.read();
if (this.messageNumber == -1)
throw new MAPException("Error creating a new SmsCommandTpdu instance: messageNumber field has not been found");
this.destinationAddress = AddressFieldImpl.createMessage(stm);
this.commandDataLength = stm.read();
if (this.commandDataLength == -1)
throw new MAPException("Error creating a new SmsCommandTpdu instance: commandDataLength field has not been found");
int avail = this.commandDataLength;
byte[] buf = new byte[avail];
try {
stm.read(buf);
} catch (IOException e) {
throw new MAPException("IOException while creating a new SmsCommandTpdu instance: " + e.getMessage(), e);
}
commandData = new CommandDataImpl(buf);
}
示例15: run
import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Override
public void run() {
byte[] buffer = new byte[1024];
DatagramPacket p = new DatagramPacket(buffer, buffer.length);
while (true) {
try {
datagramSocket.receive(p);
ByteArrayInputStream in = new ByteArrayInputStream(p.getData());
int data;
while ((data = in.read()) > -1) {
// we got a byte from the serial port
if (state == RCV_WAIT) { // it should be a start byte or we just ignore it
if (data == START_BYTE) {
state = RCV_MSG;
buffer_idx = 0;
}
} else if (state == RCV_MSG) {
if (data == ESCAPE_BYTE) {
state = RCV_ESC;
} else if (data == STOP_BYTE) {
// We got a complete frame
byte[] packet = new byte[buffer_idx];
for (int i = 0; i < buffer_idx; i++) {
packet[i] = buffer[i];
}
for (JArduinoObserver o : observers) {
o.receiveMsg(packet);
}
state = RCV_WAIT;
} else if (data == START_BYTE) {
// Should not happen but we reset just in case
state = RCV_MSG;
buffer_idx = 0;
} else { // it is just a byte to store
buffer[buffer_idx] = (byte) data;
buffer_idx++;
}
} else if (state == RCV_ESC) {
// Store the byte without looking at it
buffer[buffer_idx] = (byte) data;
buffer_idx++;
state = RCV_MSG;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}