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(); } }
/** * 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); } }
@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) { } } } }
@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(); } } } }
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(); } }
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(); } }
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(); } }
/** * 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); } }
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; }
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; }
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; }
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; }
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; }
@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) { } } } }
@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) { } } } }
@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(); } } } }
@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(); } } } }
private String encodeHeader(String header) throws IOException { String result = header; if (!stompVersion.equals(Stomp.V1_0)) { byte[] utf8buf = header.getBytes("UTF-8"); ByteArrayOutputStream stream = new ByteArrayOutputStream(utf8buf.length); for(byte val : utf8buf) { switch(val) { case Stomp.ESCAPE: stream.write(Stomp.ESCAPE_ESCAPE_SEQ); break; case Stomp.BREAK: stream.write(Stomp.NEWLINE_ESCAPE_SEQ); break; case Stomp.COLON: stream.write(Stomp.COLON_ESCAPE_SEQ); break; default: stream.write(val); } } result = new String(stream.toByteArray(), "UTF-8"); stream.close(); } return result; }
private String encodeHeader(String header) throws IOException { String result = header; if (!stompVersion.equals(Stomp.V1_0)) { byte[] utf8buf = header.getBytes("UTF-8"); ByteArrayOutputStream stream = new ByteArrayOutputStream(utf8buf.length); for(byte val : utf8buf) { switch(val) { case Stomp.ESCAPE: stream.write(Stomp.ESCAPE_ESCAPE_SEQ); break; case Stomp.BREAK: stream.write(Stomp.NEWLINE_ESCAPE_SEQ); break; case Stomp.COLON: stream.write(Stomp.COLON_ESCAPE_SEQ); break; default: stream.write(val); } } result = new String(stream.toByteArray(), "UTF-8"); stream.close(); } return result; }
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"); }