JMXChunkedOutputStreampublic class JMXChunkedOutputStream extends OutputStream
Fields Summary |
---|
private OutputStream | out | private byte[] | buffer | private int | bufCount |
Constructors Summary |
---|
public JMXChunkedOutputStream(OutputStream out)
this.out = out;
buffer = new byte[8192];
|
Methods Summary |
---|
public void | close()
if (bufCount > 0)
flush();
out.close();
| public void | flush()
if (bufCount > 0)
flushBuffer();
else
out.flush();
| private void | flushBuffer()
writeObject(buffer, 0, bufCount);
bufCount = 0;
| public void | write(byte[] b)
if (b == null)
throw (new NullPointerException("byte array is null"));
write(b, 0, b.length);
| public void | write(byte[] b, int off, int len)
if (b == null)
throw (new NullPointerException("byte array is null"));
if (off < 0 || len < 0 || (off+len) > b.length)
throw (new IndexOutOfBoundsException(
"offset="+off+
", len="+len+
", (off+len)="+(off+len)+
", b.length="+b.length+
", (off+len)>b.length="+
((off+len)>b.length)));
if (len == 0)
return;
if (bufCount > 0 && (bufCount+len) >= 8192) {
flushBuffer();
}
if (len >= 8192) {
writeObject(b, off, len);
return;
}
writeBuffer(b, off, len);
| public void | write(int by)
byte b = (byte) by;
if (bufCount > 0 && (bufCount+1) >= 8192) {
flushBuffer();
}
buffer[bufCount] = b;
bufCount++;
| private void | writeBuffer(byte[] b, int off, int len)
System.arraycopy(b, off, buffer, bufCount, len);
bufCount += len;
| public void | writeEOF(int padLen)
DataOutputStream dO = new DataOutputStream(out);
dO.writeInt(0);
// Kludge:: For some wierd reason, the StreamingOutputStream of
// HttpURLConnection is not counting the requestmessage object's
// length as the number of bytes written.
// Hence, we will send some padding bytes at the end to fool
// StreamingOutputStream.
dO.write(new byte[padLen],0,padLen);
dO.flush();
| private void | writeObject(byte[] b, int off, int len)
DataOutputStream dO = new DataOutputStream(out);
dO.writeInt(len);
dO.write(b, off, len);
dO.flush();
|
|