|
ActiveMQ example source code file (DataByteArrayInputStream.java)
The ActiveMQ DataByteArrayInputStream.java source code/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kahadb.util;
import java.io.DataInput;
import java.io.IOException;
import java.io.InputStream;
import java.io.UTFDataFormatException;
/**
* Optimized ByteArrayInputStream that can be used more than once
*
*
*/
public final class DataByteArrayInputStream extends InputStream implements DataInput {
private byte[] buf;
private int pos;
private int offset;
private int length;
/**
* Creates a <code>StoreByteArrayInputStream.
*
* @param buf the input buffer.
*/
public DataByteArrayInputStream(byte buf[]) {
this.buf = buf;
this.pos = 0;
this.offset = 0;
this.length = buf.length;
}
/**
* Creates a <code>StoreByteArrayInputStream.
*
* @param sequence the input buffer.
*/
public DataByteArrayInputStream(ByteSequence sequence) {
this.buf = sequence.getData();
this.offset = sequence.getOffset();
this.pos = this.offset;
this.length = sequence.length;
}
/**
* Creates <code>WireByteArrayInputStream with a minmalist byte
* array
*/
public DataByteArrayInputStream() {
this(new byte[0]);
}
/**
* @return the size
*/
public int size() {
return pos - offset;
}
/**
* @return the underlying data array
*/
public byte[] getRawData() {
return buf;
}
/**
* reset the <code>StoreByteArrayInputStream to use an new byte
* array
*
* @param newBuff
*/
public void restart(byte[] newBuff) {
buf = newBuff;
pos = 0;
length = newBuff.length;
}
public void restart() {
pos = 0;
length = buf.length;
}
/**
* reset the <code>StoreByteArrayInputStream to use an new
* ByteSequence
*
* @param sequence
*/
public void restart(ByteSequence sequence) {
this.buf = sequence.getData();
this.pos = sequence.getOffset();
this.length = sequence.getLength();
}
/**
* re-start the input stream - reusing the current buffer
*
* @param size
*/
public void restart(int size) {
if (buf == null || buf.length < size) {
buf = new byte[size];
}
restart(buf);
this.length = size;
}
/**
* Reads the next byte of data from this input stream. The value byte is
* returned as an <code>int in the range
Other ActiveMQ examples (source code examples)Here is a short list of links related to this ActiveMQ DataByteArrayInputStream.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.