org.apache.activemq.util.ByteArrayOutputStream.close()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.apache.activemq.util.ByteArrayOutputStream.close()方法的一些代码示例,展示了ByteArrayOutputStream.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayOutputStream.close()方法的具体详情如下:
包路径:org.apache.activemq.util.ByteArrayOutputStream
类名称:ByteArrayOutputStream
方法名:close

ByteArrayOutputStream.close介绍

暂无

代码示例

代码示例来源: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

/**
 * 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

@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

@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: org.apache.activemq/activemq-all

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: org.apache.activemq/activemq-osgi

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: org.apache.activemq/activemq-client

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: org.apache.activemq/activemq-client

/**
 * 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: 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: io.fabric8.ipaas.apps/fabric8mq

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: org.apache.activemq/activemq-osgi

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: org.apache.activemq/activemq-stomp

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: io.fabric8.jube.images.fabric8/fabric8-mq

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: org.apache.activemq/activemq-client

@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: org.apache.activemq/activemq-all

@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: org.apache.activemq/activemq-client

@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: org.apache.activemq/activemq-all

@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: org.apache.activemq/activemq-osgi

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;
}

代码示例来源:origin: org.apache.activemq/activemq-stomp

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;
}

代码示例来源: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");
}

相关文章