mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-28 21:59:09 +00:00
Wire log to include I/O errors and end of stream
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1570140 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
22d2c89b55
commit
3826597f1a
@ -51,48 +51,79 @@ public LoggingInputStream(final InputStream in, final Wire wire) {
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
final int b = in.read();
|
||||
if (b != -1) {
|
||||
wire.input(b);
|
||||
try {
|
||||
final int b = in.read();
|
||||
if (b == -1) {
|
||||
wire.input("end of stream");
|
||||
} else {
|
||||
wire.input(b);
|
||||
}
|
||||
return b;
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final byte[] b) throws IOException {
|
||||
final int bytesRead = in.read(b);
|
||||
if (bytesRead != -1) {
|
||||
wire.input(b, 0, bytesRead);
|
||||
try {
|
||||
final int bytesRead = in.read(b);
|
||||
if (bytesRead == -1) {
|
||||
wire.input("end of stream");
|
||||
} else if (bytesRead > 0) {
|
||||
wire.input(b, 0, bytesRead);
|
||||
}
|
||||
return bytesRead;
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final byte[] b, final int off, final int len) throws IOException {
|
||||
final int bytesRead = in.read(b, off, len);
|
||||
if (bytesRead != -1) {
|
||||
wire.input(b, off, bytesRead);
|
||||
try {
|
||||
final int bytesRead = in.read(b, off, len);
|
||||
if (bytesRead == -1) {
|
||||
wire.input("end of stream");
|
||||
} else if (bytesRead > 0) {
|
||||
wire.input(b, off, bytesRead);
|
||||
}
|
||||
return bytesRead;
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(final long n) throws IOException {
|
||||
return super.skip(n);
|
||||
try {
|
||||
return super.skip(n);
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return in.available();
|
||||
try {
|
||||
return in.available();
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void mark(final int readlimit) {
|
||||
public void mark(final int readlimit) {
|
||||
super.mark(readlimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reset() throws IOException {
|
||||
public void reset() throws IOException {
|
||||
super.reset();
|
||||
}
|
||||
|
||||
@ -103,7 +134,12 @@ public boolean markSupported() {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
in.close();
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,29 +51,54 @@ public LoggingOutputStream(final OutputStream out, final Wire wire) {
|
||||
|
||||
@Override
|
||||
public void write(final int b) throws IOException {
|
||||
wire.output(b);
|
||||
try {
|
||||
wire.output(b);
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final byte[] b) throws IOException {
|
||||
wire.output(b);
|
||||
out.write(b);
|
||||
try {
|
||||
wire.output(b);
|
||||
out.write(b);
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final byte[] b, final int off, final int len) throws IOException {
|
||||
wire.output(b, off, len);
|
||||
out.write(b, off, len);
|
||||
try {
|
||||
wire.output(b, off, len);
|
||||
out.write(b, off, len);
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
out.flush();
|
||||
try {
|
||||
out.flush();
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
out.close();
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ex) {
|
||||
wire.input("I/O error: " + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -138,20 +138,12 @@ public void input(final int b)
|
||||
input(new byte[] {(byte) b});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated (4.1) do not use
|
||||
*/
|
||||
@Deprecated
|
||||
public void output(final String s)
|
||||
throws IOException {
|
||||
Args.notNull(s, "Output");
|
||||
output(s.getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated (4.1) do not use
|
||||
*/
|
||||
@Deprecated
|
||||
public void input(final String s)
|
||||
throws IOException {
|
||||
Args.notNull(s, "Input");
|
||||
|
Loading…
x
Reference in New Issue
Block a user