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,12 +15,12 @@ import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec;
*/
public class EdDSAPrivateKey implements EdDSAKey, PrivateKey {
private static final long serialVersionUID = 23495873459878957L;
private transient final byte[] seed;
private transient final byte[] h;
private transient final byte[] a;
private transient final GroupElement A;
private transient final byte[] Abyte;
private transient final EdDSAParameterSpec edDsaSpec;
private final byte[] seed;
private final byte[] h;
private final byte[] a;
private final GroupElement A;
private final byte[] Abyte;
private final EdDSAParameterSpec edDsaSpec;
public EdDSAPrivateKey(EdDSAPrivateKeySpec spec) {
this.seed = spec.getSeed();

View File

@ -101,8 +101,8 @@ public class Base32 {
}
private static byte[] read(InputStream in) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
byte buf[] = new byte[4096];
ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
byte buf[] = new byte[64];
while (true) {
int read = in.read(buf);
if (read < 0) break;
@ -118,7 +118,7 @@ public class Base32 {
}
private static void decode(InputStream in, OutputStream out) throws IOException {
byte decoded[] = decode(new String(read(in)));
byte decoded[] = decode(DataHelper.getUTF8(read(in)));
if (decoded == null) {
System.out.println("FAIL");
return;
@ -199,7 +199,7 @@ public class Base32 {
byte[] b = decode(s);
if (b == null)
return null;
return new String(b);
return DataHelper.getUTF8(b);
}
/**

View File

@ -246,8 +246,8 @@ public class Base64 {
}
private static byte[] read(InputStream in) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
byte buf[] = new byte[4096];
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
byte buf[] = new byte[1024];
while (true) {
int read = in.read(buf);
if (read < 0) break;
@ -263,7 +263,7 @@ public class Base64 {
}
private static void decode(InputStream in, OutputStream out) throws IOException {
byte decoded[] = decode(new String(read(in)));
byte decoded[] = decode(DataHelper.getUTF8(read(in)));
if (decoded == null)
throw new IOException("Invalid base 64 string");
out.write(decoded);

View File

@ -262,7 +262,7 @@ public class Certificate extends DataStructureImpl {
} else {
buf.append(" payload size: ").append(_payload.length);
if (getCertificateType() == CERTIFICATE_TYPE_HASHCASH) {
buf.append(" Stamp: ").append(new String(_payload));
buf.append(" Stamp: ").append(DataHelper.getUTF8(_payload));
} else if (getCertificateType() == CERTIFICATE_TYPE_SIGNED && _payload.length == CERTIFICATE_LENGTH_SIGNED_WITH_HASH) {
buf.append(" Signed by hash: ").append(Base64.encode(_payload, Signature.SIGNATURE_BYTES, Hash.HASH_LENGTH));
} else {

View File

@ -1864,7 +1864,6 @@ public class DataHelper {
*
* @return null if orig is null
* @throws RuntimeException
* @deprecated unused
*/
public static String getUTF8(byte orig[], int offset, int len) {
if (orig == null) return null;

View File

@ -87,7 +87,7 @@ public class VerifiedDestination extends Destination {
* zeros and see if it meets our minimum effort.
*/
protected boolean verifyHashCashCert() {
String hcs = new String(_certificate.getPayload());
String hcs = DataHelper.getUTF8(_certificate.getPayload());
int end1 = 0;
for (int i = 0; i < 3; i++) {
end1 = 1 + hcs.indexOf(':', end1);

View File

@ -9,12 +9,13 @@ package net.i2p.util;
*
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
/**
* Render a log record according to the log manager's settings
@ -71,16 +72,11 @@ class LogRecordFormatter {
}
buf.append(NL);
if (rec.getThrowable() != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
PrintWriter pw = new PrintWriter(baos, true);
StringWriter sw = new StringWriter(512);
PrintWriter pw = new PrintWriter(sw, true);
rec.getThrowable().printStackTrace(pw);
try {
pw.flush();
baos.flush();
} catch (IOException ioe) { // nop
}
byte tb[] = baos.toByteArray();
buf.append(new String(tb));
sw.flush();
buf.append(sw.toString());
}
return buf.toString();
}