本文整理了Java中org.apache.activemq.util.ByteArrayOutputStream
类的一些代码示例,展示了ByteArrayOutputStream
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayOutputStream
类的具体详情如下:
包路径:org.apache.activemq.util.ByteArrayOutputStream
类名称:ByteArrayOutputStream
[英]Very similar to the java.io.ByteArrayOutputStream but this version is not thread safe and the resulting data is returned in a ByteSequence to avoid an extra byte[] allocation.
[中]与java非常相似。木卫一。ByteArrayOutputStream,但此版本不是线程安全的,结果数据以字节顺序返回,以避免额外的字节[]分配。
代码示例来源:origin: apache/activemq
@Override
public void beforeMarshall(WireFormat wireFormat) throws IOException {
// Need to marshal the properties.
if (marshalledProperties == null && properties != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(baos);
MarshallingSupport.marshalPrimitiveMap(properties, os);
os.close();
marshalledProperties = baos.toByteSequence();
}
}
代码示例来源:origin: apache/activemq
DataOutputStream dataOut = new DataOutputStream(writeBuffer);
headerMarshaller.writeHeader(command, dataOut);
int offset = writeBuffer.size();
} else {
byte[] data = writeBuffer.toByteArray();
boolean lastFragment = false;
int length = data.length;
dataOut.writeInt(chunkSize);
chunkSize -= 4;
dataOut.write(LastPartialCommand.DATA_STRUCTURE_TYPE);
} else {
dataOut.write(PartialCommand.DATA_STRUCTURE_TYPE);
代码示例来源:origin: apache/activemq
protected byte[] decompress(ByteSequence dataSequence) throws IOException {
Inflater inflater = new Inflater();
ByteArrayOutputStream decompressed = new ByteArrayOutputStream();
try {
length = ByteSequenceData.readIntBig(dataSequence);
dataSequence.offset = 0;
byte[] data = Arrays.copyOfRange(dataSequence.getData(), 4, dataSequence.getLength());
inflater.setInput(data);
byte[] buffer = new byte[length];
int count = inflater.inflate(buffer);
decompressed.write(buffer, 0, count);
return decompressed.toByteArray();
} catch (Exception e) {
throw new IOException(e);
} finally {
inflater.end();
decompressed.close();
}
}
代码示例来源:origin: apache/activemq
protected void doCompress() throws IOException {
compressed = true;
ByteSequence bytes = getContent();
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = new DeflaterOutputStream(bytesOut);
os.write(bytes.data, bytes.offset, bytes.length);
os.close();
setContent(bytesOut.toByteSequence());
}
代码示例来源:origin: apache/activemq
@Override
public void storeContent() {
try {
if (getContent() == null && !map.isEmpty()) {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
MarshallingSupport.marshalPrimitiveMap(map, dataOut);
dataOut.close();
setContent(bytesOut.toByteSequence());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/activemq
@Override
public void storeContent() {
try {
ByteSequence content = getContent();
String text = this.text;
if (content == null && text != null) {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
MarshallingSupport.writeUTF8(dataOut, text);
dataOut.close();
setContent(bytesOut.toByteSequence());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: io.fabric8.ipaas.apps/fabric8mq
ActiveMQTextMessage text = new ActiveMQTextMessage();
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(command.getContent().length + 4);
DataOutputStream data = new DataOutputStream(bytes);
data.writeInt(command.getContent().length);
data.write(command.getContent());
text.setContent(bytes.toByteSequence());
data.close();
} catch (Throwable e) {
ActiveMQBytesMessage byteMessage = new ActiveMQBytesMessage();
byteMessage.writeBytes(command.getContent());
msg = byteMessage;
} else {
ActiveMQBytesMessage bm = new ActiveMQBytesMessage();
bm.writeBytes(command.getContent());
msg = bm;
ActiveMQTextMessage text = new ActiveMQTextMessage();
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(command.getContent().length + 4);
DataOutputStream data = new DataOutputStream(bytes);
data.writeInt(command.getContent().length);
data.write(command.getContent());
text.setContent(bytes.toByteSequence());
data.close();
} catch (Throwable e) {
代码示例来源:origin: apache/activemq
private void trace(DataStructure command) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(maxTraceDatagramSize);
DataOutputStream out = new DataOutputStream(baos);
wireFormat.marshal(brokerId, out);
wireFormat.marshal(command, out);
out.close();
ByteSequence sequence = baos.toByteSequence();
DatagramPacket datagram = new DatagramPacket(sequence.getData(), sequence.getOffset(), sequence.getLength(), address);
socket.send(datagram);
} catch (Throwable e) {
LOG.debug("Failed to trace: {}", command, e);
}
}
代码示例来源:origin: apache/activemq
@Override
public void storeContent() {
ByteSequence bodyAsBytes = getContent();
if (bodyAsBytes == null && object != null) {
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
ObjectOutputStream objOut = new ObjectOutputStream(dataOut);
objOut.writeObject(object);
objOut.flush();
objOut.reset();
objOut.close();
setContent(bytesOut.toByteSequence());
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage(), ioe);
}
}
}
代码示例来源:origin: apache/activemq
private void initializeWriting() throws JMSException {
checkReadOnlyBody();
if (this.dataOut == null) {
this.bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
this.dataOut = new DataOutputStream(os);
}
restoreOldContent();
}
代码示例来源:origin: apache/activemq
private void initializeWriting() throws JMSException {
checkReadOnlyBody();
if (this.dataOut == null) {
this.bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
os = new DeflaterOutputStream(os);
this.dataOut = new DataOutputStream(os);
try {
if (compressed) {
ByteArrayInputStream input = new ByteArrayInputStream(this.content.getData(), this.content.getOffset(), this.content.getLength());
InflaterInputStream inflater = new InflaterInputStream(input);
try {
int read = 0;
while ((read = inflater.read(buffer)) != -1) {
this.dataOut.write(buffer, 0, read);
this.dataOut.write(this.content.getData(), this.content.getOffset(), this.content.getLength());
代码示例来源:origin: pierre/meteo
private void initializeWriting() throws JMSException {
checkReadOnlyBody();
if (this.dataOut == null) {
this.bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
final Deflater deflater = new Deflater(Deflater.BEST_SPEED);
os = new FilterOutputStream(new DeflaterOutputStream(os, deflater)) {
public void write(byte[] arg0) throws IOException {
length += arg0.length;
this.dataOut = new DataOutputStream(os);
代码示例来源:origin: apache/activemq
@Override
public void storeContent() {
if (dataOut != null) {
try {
dataOut.close();
ByteSequence bs = bytesOut.toByteSequence();
setContent(bs);
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
doCompress();
}
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage(), ioe);
} finally {
try {
if (bytesOut != null) {
bytesOut.close();
bytesOut = null;
}
if (dataOut != null) {
dataOut.close();
dataOut = null;
}
} catch (IOException ioe) {
}
}
}
}
代码示例来源:origin: apache/activemq
/**
* Puts the message body in read-only mode and repositions the stream of
* bytes to the beginning.
*
* @throws JMSException if an internal error occurs
*/
@Override
public void reset() throws JMSException {
storeContent();
setReadOnlyBody(true);
try {
if (bytesOut != null) {
bytesOut.close();
bytesOut = null;
}
if (dataIn != null) {
dataIn.close();
dataIn = null;
}
if (dataOut != null) {
dataOut.close();
dataOut = null;
}
} catch (IOException ioe) {
throw JMSExceptionSupport.create(ioe);
}
}
代码示例来源:origin: apache/activemq
public void write(Command command, SocketAddress address) throws IOException {
synchronized (writeLock) {
ByteArrayOutputStream largeBuffer = new ByteArrayOutputStream(defaultMarshalBufferSize);
wireFormat.marshal(command, new DataOutputStream(largeBuffer));
byte[] data = largeBuffer.toByteArray();
int size = data.length;
代码示例来源:origin: apache/activemq
@Override
public void storeContent() {
if (dataOut != null) {
try {
dataOut.close();
setContent(bytesOut.toByteSequence());
bytesOut = null;
dataOut = null;
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
}
代码示例来源:origin: pierre/meteo
private void storeContent() {
try {
if (dataOut != null) {
dataOut.close();
ByteSequence bs = bytesOut.toByteSequence();
if (compressed) {
int pos = bs.offset;
ByteSequenceData.writeIntBig(bs, length);
bs.offset = pos;
}
setContent(bs);
bytesOut = null;
dataOut = null;
}
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage(), ioe); // TODO verify
// RuntimeException
}
}
代码示例来源:origin: org.apache.activemq/activemq-all
private ByteSequence readHeaderLine(DataInput in, int maxLength, String errorMessage) throws IOException {
byte b;
ByteArrayOutputStream baos = new ByteArrayOutputStream(maxLength);
while ((b = in.readByte()) != '\n') {
if (baos.size() > maxLength) {
baos.close();
throw new ProtocolException(errorMessage, true);
}
baos.write(b);
}
baos.close();
ByteSequence line = baos.toByteSequence();
if (stompVersion.equals(Stomp.V1_0) || stompVersion.equals(Stomp.V1_2)) {
int lineLength = line.getLength();
if (lineLength > 0 && line.data[lineLength-1] == '\r') {
line.setLength(lineLength-1);
}
}
return line;
}
代码示例来源:origin: apache/activemq
@Override
protected void doCompress() throws IOException {
compressed = true;
ByteSequence bytes = getContent();
if (bytes != null) {
int length = bytes.getLength();
ByteArrayOutputStream compressed = new ByteArrayOutputStream();
compressed.write(new byte[4]);
Deflater deflater = new Deflater();
try {
deflater.setInput(bytes.data);
deflater.finish();
byte[] buffer = new byte[1024];
while (!deflater.finished()) {
int count = deflater.deflate(buffer);
compressed.write(buffer, 0, count);
}
bytes = compressed.toByteSequence();
ByteSequenceData.writeIntBig(bytes, length);
bytes.offset = 0;
setContent(bytes);
} finally {
deflater.end();
compressed.close();
}
}
}
}
代码示例来源:origin: pierre/meteo
private String readLine(DataInput in, int maxLength, String errorMessage) throws IOException {
byte b;
ByteArrayOutputStream baos = new ByteArrayOutputStream(maxLength);
while ((b = in.readByte()) != '\n') {
if (baos.size() > maxLength) {
throw new ProtocolException(errorMessage, true);
}
baos.write(b);
}
baos.close();
ByteSequence sequence = baos.toByteSequence();
return new String(sequence.getData(), sequence.getOffset(), sequence.getLength(), "UTF-8");
}
内容来源于网络,如有侵权,请联系作者删除!