HTTPCLIENT-940: deprecated methods dependent on the default charset

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@943614 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2010-05-12 18:20:11 +00:00
parent 366e154d10
commit bb0ecdbcb4
4 changed files with 41 additions and 9 deletions

View File

@ -43,6 +43,7 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.impl.SocketHttpClientConnection;
import org.apache.http.io.HttpMessageParser;
@ -174,7 +175,10 @@ public class DefaultClientConnection extends SocketHttpClientConnection
buffersize,
params);
if (wireLog.isDebugEnabled()) {
inbuffer = new LoggingSessionInputBuffer(inbuffer, new Wire(wireLog));
inbuffer = new LoggingSessionInputBuffer(
inbuffer,
new Wire(wireLog),
HttpProtocolParams.getHttpElementCharset(params));
}
return inbuffer;
}
@ -192,7 +196,10 @@ public class DefaultClientConnection extends SocketHttpClientConnection
buffersize,
params);
if (wireLog.isDebugEnabled()) {
outbuffer = new LoggingSessionOutputBuffer(outbuffer, new Wire(wireLog));
outbuffer = new LoggingSessionOutputBuffer(
outbuffer,
new Wire(wireLog),
HttpProtocolParams.getHttpElementCharset(params));
}
return outbuffer;
}

View File

@ -32,6 +32,7 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.io.HttpTransportMetrics;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.CharArrayBuffer;
/**
@ -49,15 +50,24 @@ public class LoggingSessionInputBuffer implements SessionInputBuffer {
/** The wire log to use for writing. */
private final Wire wire;
private String charset;
/**
* Create an instance that wraps the specified session input buffer.
* @param in The session input buffer.
* @param wire The wire log to use.
* @param charset protocol charset, <code>ASCII</code> if <code>null</code>
*/
public LoggingSessionInputBuffer(final SessionInputBuffer in, final Wire wire) {
public LoggingSessionInputBuffer(
final SessionInputBuffer in, final Wire wire, final String charset) {
super();
this.in = in;
this.wire = wire;
this.charset = charset != null ? charset : HTTP.ASCII;
}
public LoggingSessionInputBuffer(final SessionInputBuffer in, final Wire wire) {
this(in, wire, null);
}
public boolean isDataAvailable(int timeout) throws IOException {
@ -91,7 +101,8 @@ public class LoggingSessionInputBuffer implements SessionInputBuffer {
public String readLine() throws IOException {
String s = this.in.readLine();
if (this.wire.enabled() && s != null) {
this.wire.input(s + "[EOL]");
String tmp = s + "\r\n";
this.wire.input(tmp.getBytes(this.charset));
}
return s;
}
@ -101,7 +112,8 @@ public class LoggingSessionInputBuffer implements SessionInputBuffer {
if (this.wire.enabled() && l >= 0) {
int pos = buffer.length() - l;
String s = new String(buffer.buffer(), pos, l);
this.wire.input(s + "[EOL]");
String tmp = s + "\r\n";
this.wire.input(tmp.getBytes(this.charset));
}
return l;
}

View File

@ -32,6 +32,7 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.io.HttpTransportMetrics;
import org.apache.http.io.SessionOutputBuffer;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.CharArrayBuffer;
/**
@ -49,15 +50,24 @@ public class LoggingSessionOutputBuffer implements SessionOutputBuffer {
/** The wire log to use. */
private final Wire wire;
private String charset;
/**
* Create an instance that wraps the specified session output buffer.
* @param out The session output buffer.
* @param wire The Wire log to use.
* @param charset protocol charset, <code>ASCII</code> if <code>null</code>
*/
public LoggingSessionOutputBuffer(final SessionOutputBuffer out, final Wire wire) {
public LoggingSessionOutputBuffer(
final SessionOutputBuffer out, final Wire wire, final String charset) {
super();
this.out = out;
this.wire = wire;
this.charset = charset != null ? charset : HTTP.ASCII;
}
public LoggingSessionOutputBuffer(final SessionOutputBuffer out, final Wire wire) {
this(out, wire, null);
}
public void write(byte[] b, int off, int len) throws IOException {
@ -89,14 +99,16 @@ public class LoggingSessionOutputBuffer implements SessionOutputBuffer {
this.out.writeLine(buffer);
if (this.wire.enabled()) {
String s = new String(buffer.buffer(), 0, buffer.length());
this.wire.output(s + "[EOL]");
String tmp = s + "\r\n";
this.wire.output(tmp.getBytes(this.charset));
}
}
public void writeLine(final String s) throws IOException {
this.out.writeLine(s);
if (this.wire.enabled()) {
this.wire.output(s + "[EOL]");
String tmp = s + "\r\n";
this.wire.output(tmp.getBytes(this.charset));
}
}

View File

@ -1,5 +1,4 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/Wire.java,v 1.9 2004/06/24 21:39:52 mbecke Exp $
* ====================================================================
*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -142,6 +141,7 @@ public class Wire {
input(new byte[] {(byte) b});
}
@Deprecated
public void output(final String s)
throws IOException {
if (s == null) {
@ -150,6 +150,7 @@ public class Wire {
output(s.getBytes());
}
@Deprecated
public void input(final String s)
throws IOException {
if (s == null) {