mirror of https://github.com/apache/activemq.git
optimized
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@470389 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
330e73140a
commit
fdcc973923
|
@ -32,6 +32,7 @@ import java.io.OutputStream;
|
||||||
public class TcpBufferedOutputStream extends FilterOutputStream {
|
public class TcpBufferedOutputStream extends FilterOutputStream {
|
||||||
private final static int BUFFER_SIZE = 8192;
|
private final static int BUFFER_SIZE = 8192;
|
||||||
private byte[] buffer;
|
private byte[] buffer;
|
||||||
|
private int bufferlen;
|
||||||
private int count;
|
private int count;
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ public class TcpBufferedOutputStream extends FilterOutputStream {
|
||||||
throw new IllegalArgumentException("Buffer size <= 0");
|
throw new IllegalArgumentException("Buffer size <= 0");
|
||||||
}
|
}
|
||||||
buffer = new byte[size];
|
buffer = new byte[size];
|
||||||
|
bufferlen=size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,8 +69,7 @@ public class TcpBufferedOutputStream extends FilterOutputStream {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void write(int b) throws IOException {
|
public void write(int b) throws IOException {
|
||||||
checkClosed();
|
if ((bufferlen-count) < 1) {
|
||||||
if (availableBufferToWrite() < 1) {
|
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
buffer[count++] = (byte) b;
|
buffer[count++] = (byte) b;
|
||||||
|
@ -84,8 +85,7 @@ public class TcpBufferedOutputStream extends FilterOutputStream {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void write(byte b[], int off, int len) throws IOException {
|
public void write(byte b[], int off, int len) throws IOException {
|
||||||
checkClosed();
|
if ((bufferlen-count) < len) {
|
||||||
if (availableBufferToWrite() < len) {
|
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
if (buffer.length >= len) {
|
if (buffer.length >= len) {
|
||||||
|
@ -127,16 +127,10 @@ public class TcpBufferedOutputStream extends FilterOutputStream {
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected void checkClosed() throws IOException {
|
private final void checkClosed() throws IOException {
|
||||||
if (closed) {
|
if (closed) {
|
||||||
throw new EOFException("Cannot write to the stream any more it has already been closed");
|
throw new EOFException("Cannot write to the stream any more it has already been closed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the amount free space in the buffer
|
|
||||||
*/
|
|
||||||
private int availableBufferToWrite() {
|
|
||||||
return buffer.length - count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue