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

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

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

ByteArrayOutputStream.write介绍

暂无

代码示例

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

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

@Override
public byte[] doGetMessage(TransactionContext c, MessageId id) throws SQLException, IOException {
  PreparedStatement s = null;
  ResultSet rs = null;
  try {
    s = c.getConnection().prepareStatement(statements.getFindMessageStatement());
    s.setString(1, id.getProducerId().toString());
    s.setLong(2, id.getProducerSequenceId());
    rs = s.executeQuery();
    if (!rs.next()) {
      return null;
    }
    Blob blob = rs.getBlob(1);
    try(InputStream is = blob.getBinaryStream();
      ByteArrayOutputStream os = new ByteArrayOutputStream((int)blob.length())) {
      int ch;
      while ((ch = is.read()) >= 0) {
        os.write(ch);
      }
      return os.toByteArray();
    }
  } finally {
    close(rs);
    close(s);
  }
}

代码示例来源:origin: io.fabric8.ipaas.apps/fabric8mq

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");
  }
  return result;
}

代码示例来源:origin: io.fabric8.jube.images.fabric8/fabric8-mq

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");
  }
  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: 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: apache/activemq-artemis

private static byte[] toAMQMessageCompressedBytesType(final byte[] bytes) throws IOException {
 int length = bytes.length;
 Deflater deflater = new Deflater();
 try (org.apache.activemq.util.ByteArrayOutputStream compressed = new org.apache.activemq.util.ByteArrayOutputStream()) {
   compressed.write(new byte[4]);
   deflater.setInput(bytes);
   deflater.finish();
   byte[] bytesBuf = new byte[1024];
   while (!deflater.finished()) {
    int count = deflater.deflate(bytesBuf);
    compressed.write(bytesBuf, 0, count);
   }
   compressed.flush();
   ByteSequence byteSeq = compressed.toByteSequence();
   ByteSequenceData.writeIntBig(byteSeq, length);
   return Arrays.copyOfRange(byteSeq.data, 0, byteSeq.length);
 } finally {
   deflater.end();
 }
}

代码示例来源:origin: apache/activemq-artemis

private static ByteSequence writeCompressedObjectType(final ByteSequence contents) throws IOException {
 try (InputStream ois = new InflaterInputStream(new ByteArrayInputStream(contents));
    org.apache.activemq.util.ByteArrayOutputStream decompressed = new org.apache.activemq.util.ByteArrayOutputStream()) {
   byte[] buf = new byte[1024];
   int n = ois.read(buf);
   while (n != -1) {
    decompressed.write(buf, 0, n);
    n = ois.read();
   }
   //read done
   return decompressed.toByteSequence();
 }
}

代码示例来源:origin: apache/activemq-artemis

private static ByteSequence writeCompressedBytesType(final ByteSequence contents) throws IOException {
 Inflater inflater = new Inflater();
 try (org.apache.activemq.util.ByteArrayOutputStream decompressed = new org.apache.activemq.util.ByteArrayOutputStream()) {
   int length = ByteSequenceData.readIntBig(contents);
   contents.offset = 0;
   byte[] data = Arrays.copyOfRange(contents.getData(), 4, contents.getLength());
   inflater.setInput(data);
   byte[] buffer = new byte[length];
   int count = inflater.inflate(buffer);
   decompressed.write(buffer, 0, count);
   return decompressed.toByteSequence();
 } catch (Exception e) {
   throw new IOException(e);
 } finally {
   inflater.end();
 }
}

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

@Override
public byte[] doGetMessage(TransactionContext c, MessageId id) throws SQLException, IOException {
  PreparedStatement s = null;
  ResultSet rs = null;
  try {
    s = c.getConnection().prepareStatement(statements.getFindMessageStatement());
    s.setString(1, id.getProducerId().toString());
    s.setLong(2, id.getProducerSequenceId());
    rs = s.executeQuery();
    if (!rs.next()) {
      return null;
    }
    Blob blob = rs.getBlob(1);
    try(InputStream is = blob.getBinaryStream();
      ByteArrayOutputStream os = new ByteArrayOutputStream((int)blob.length())) {
      int ch;
      while ((ch = is.read()) >= 0) {
        os.write(ch);
      }
      return os.toByteArray();
    }
  } finally {
    close(rs);
    close(s);
  }
}

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

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

相关文章