Methods Summary |
---|
public void | flush()
flushBuffer();
this.outstream.flush();
|
protected void | flushBuffer()
int len = this.buffer.length();
if (len > 0) {
this.outstream.write(this.buffer.buffer(), 0, len);
this.buffer.clear();
this.metrics.incrementBytesTransferred(len);
}
|
public org.apache.http.io.HttpTransportMetrics | getMetrics()
return this.metrics;
|
protected void | init(java.io.OutputStream outstream, int buffersize, org.apache.http.params.HttpParams params)
if (outstream == null) {
throw new IllegalArgumentException("Input stream may not be null");
}
if (buffersize <= 0) {
throw new IllegalArgumentException("Buffer size may not be negative or zero");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.outstream = outstream;
this.buffer = new ByteArrayBuffer(buffersize);
this.charset = HttpProtocolParams.getHttpElementCharset(params);
this.ascii = this.charset.equalsIgnoreCase(HTTP.US_ASCII)
|| this.charset.equalsIgnoreCase(HTTP.ASCII);
this.metrics = new HttpTransportMetricsImpl();
|
public void | write(byte[] b, int off, int len)
if (b == null) {
return;
}
// Do not want to buffer largish chunks
// if the byte array is larger then MAX_CHUNK
// write it directly to the output stream
if (len > MAX_CHUNK || len > this.buffer.capacity()) {
// flush the buffer
flushBuffer();
// write directly to the out stream
this.outstream.write(b, off, len);
this.metrics.incrementBytesTransferred(len);
} else {
// Do not let the buffer grow unnecessarily
int freecapacity = this.buffer.capacity() - this.buffer.length();
if (len > freecapacity) {
// flush the buffer
flushBuffer();
}
// buffer
this.buffer.append(b, off, len);
}
|
public void | write(byte[] b)
if (b == null) {
return;
}
write(b, 0, b.length);
|
public void | write(int b)
if (this.buffer.isFull()) {
flushBuffer();
}
this.buffer.append(b);
|
public void | writeLine(java.lang.String s)
if (s == null) {
return;
}
if (s.length() > 0) {
write(s.getBytes(this.charset));
}
write(CRLF);
|
public void | writeLine(org.apache.http.util.CharArrayBuffer s)
if (s == null) {
return;
}
if (this.ascii) {
int off = 0;
int remaining = s.length();
while (remaining > 0) {
int chunk = this.buffer.capacity() - this.buffer.length();
chunk = Math.min(chunk, remaining);
if (chunk > 0) {
this.buffer.append(s, off, chunk);
}
if (this.buffer.isFull()) {
flushBuffer();
}
off += chunk;
remaining -= chunk;
}
} else {
// This is VERY memory inefficient, BUT since non-ASCII charsets are
// NOT meant to be used anyway, there's no point optimizing it
byte[] tmp = s.toString().getBytes(this.charset);
write(tmp);
}
write(CRLF);
|