Findbugs all over #2

Mostly char encoding
Use StringWriter rather than OSW->BAOS->String
This commit is contained in:
zzz
2015-07-12 16:06:49 +00:00
parent 914cc120ad
commit 1f9bb046f5
25 changed files with 76 additions and 68 deletions

View File

@ -15,6 +15,7 @@ import java.util.Locale;
import net.i2p.I2PAppContext;
import net.i2p.data.ByteArray;
import net.i2p.data.DataHelper;
import net.i2p.util.ByteCache;
import net.i2p.util.Log;
@ -145,7 +146,7 @@ class HTTPResponseOutputStream extends FilterOutputStream {
for (int i = 0; i < _headerBuffer.getValid(); i++) {
if (isNL(_headerBuffer.getData()[i])) {
if (lastEnd == -1) {
responseLine = new String(_headerBuffer.getData(), 0, i+1); // includes NL
responseLine = DataHelper.getUTF8(_headerBuffer.getData(), 0, i+1); // includes NL
responseLine = filterResponseLine(responseLine);
responseLine = (responseLine.trim() + "\r\n");
if (_log.shouldLog(Log.INFO))
@ -158,12 +159,12 @@ class HTTPResponseOutputStream extends FilterOutputStream {
int valLen = i-(j+1);
if ( (keyLen <= 0) || (valLen < 0) )
throw new IOException("Invalid header @ " + j);
String key = new String(_headerBuffer.getData(), lastEnd+1, keyLen);
String key = DataHelper.getUTF8(_headerBuffer.getData(), lastEnd+1, keyLen);
String val = null;
if (valLen == 0)
val = "";
else
val = new String(_headerBuffer.getData(), j+2, valLen).trim();
val = DataHelper.getUTF8(_headerBuffer.getData(), j+2, valLen).trim();
if (_log.shouldLog(Log.INFO))
_log.info("Response header [" + key + "] = [" + val + "]");

View File

@ -24,6 +24,7 @@ import net.i2p.I2PException;
import net.i2p.client.streaming.I2PSocket;
import net.i2p.client.streaming.I2PSocketOptions;
import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
import net.i2p.i2ptunnel.I2PTunnelHTTPClientBase;
import net.i2p.i2ptunnel.I2PTunnel;
@ -226,7 +227,7 @@ public class SOCKS5Server extends SOCKSServer {
}
byte addr[] = new byte[addrLen];
in.readFully(addr);
connHostName = new String(addr);
connHostName = DataHelper.getUTF8(addr);
}
_log.debug("DOMAINNAME address type in request: " + connHostName);
break;

View File

@ -1,6 +1,7 @@
package net.i2p.i2ptunnel.socks;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;
/**
@ -65,7 +66,7 @@ public class SOCKSHeader {
int namelen = (this.header[4] & 0xff);
byte[] nameBytes = new byte[namelen];
System.arraycopy(nameBytes, 0, this.header, 5, namelen);
return new String(nameBytes);
return DataHelper.getUTF8(nameBytes);
}
public Destination getDestination() {