forked from I2P_Developers/i2p.i2p
merge of '03e8a3d066ce112bb4ddaa98c0387dfefde94a0e'
and '751ff97c62634ee13a8f8baf3d7947e373d5368a'
This commit is contained in:
@@ -9,8 +9,6 @@ public class Address extends DataStructureImpl {
|
||||
private Destination _destination;
|
||||
|
||||
public Address() {
|
||||
_hostname = null;
|
||||
_destination = null;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
|
||||
@@ -22,11 +22,9 @@ public class ByteArray implements Serializable, Comparable {
|
||||
private int _offset;
|
||||
|
||||
public ByteArray() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ByteArray(byte[] data) {
|
||||
_offset = 0;
|
||||
_data = data;
|
||||
_valid = (data != null ? data.length : 0);
|
||||
}
|
||||
@@ -92,4 +90,4 @@ public class ByteArray implements Serializable, Comparable {
|
||||
public final String toBase64() {
|
||||
return Base64.encode(_data, _offset, _valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,6 @@ public class Certificate extends DataStructureImpl {
|
||||
public final static int CERTIFICATE_TYPE_MULTIPLE = 4;
|
||||
|
||||
public Certificate() {
|
||||
_type = 0;
|
||||
_payload = null;
|
||||
}
|
||||
|
||||
public Certificate(int type, byte[] payload) {
|
||||
|
||||
@@ -27,10 +27,6 @@ public class Destination extends DataStructureImpl {
|
||||
protected Hash __calculatedHash;
|
||||
|
||||
public Destination() {
|
||||
setCertificate(null);
|
||||
setSigningPublicKey(null);
|
||||
setPublicKey(null);
|
||||
__calculatedHash = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +34,6 @@ public class Destination extends DataStructureImpl {
|
||||
* @param s a Base64 representation of the destination, as (eg) is used in hosts.txt
|
||||
*/
|
||||
public Destination(String s) throws DataFormatException {
|
||||
this();
|
||||
fromBase64(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,13 +12,6 @@ package net.i2p.data;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Defines the hash as defined by the I2P data structure spec.
|
||||
@@ -27,20 +20,15 @@ import net.i2p.util.Log;
|
||||
* @author jrandom
|
||||
*/
|
||||
public class Hash extends DataStructureImpl {
|
||||
private final static Log _log = new Log(Hash.class);
|
||||
private byte[] _data;
|
||||
private volatile String _stringified;
|
||||
private volatile String _base64ed;
|
||||
private /* FIXME final FIXME */ Map _xorCache;
|
||||
private int _cachedHashCode;
|
||||
|
||||
public final static int HASH_LENGTH = 32;
|
||||
public final static Hash FAKE_HASH = new Hash(new byte[HASH_LENGTH]);
|
||||
|
||||
private static final int MAX_CACHED_XOR = 1024;
|
||||
|
||||
public Hash() {
|
||||
setData(null);
|
||||
}
|
||||
|
||||
public Hash(byte data[]) {
|
||||
@@ -58,77 +46,6 @@ public class Hash extends DataStructureImpl {
|
||||
_cachedHashCode = calcHashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare this hash's cache for xor values - very few hashes will need it,
|
||||
* so we don't want to waste the memory, and lazy initialization would incur
|
||||
* online overhead to verify the initialization.
|
||||
*
|
||||
*/
|
||||
public void prepareCache() {
|
||||
synchronized (this) {
|
||||
if (_xorCache == null)
|
||||
_xorCache = new HashMap(MAX_CACHED_XOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the xor with the current object and the specified hash,
|
||||
* caching values where possible. Currently this keeps up to MAX_CACHED_XOR
|
||||
* (1024) entries, and uses an essentially random ejection policy. Later
|
||||
* perhaps go for an LRU or FIFO?
|
||||
*
|
||||
* @throws IllegalStateException if you try to use the cache without first
|
||||
* preparing this object's cache via .prepareCache()
|
||||
*/
|
||||
public byte[] cachedXor(Hash key) throws IllegalStateException {
|
||||
if (_xorCache == null)
|
||||
throw new IllegalStateException("To use the cache, you must first prepare it");
|
||||
byte[] distance = (byte[])_xorCache.get(key);
|
||||
|
||||
if (distance == null) {
|
||||
// not cached, lets cache it
|
||||
int cached = 0;
|
||||
synchronized (_xorCache) {
|
||||
int toRemove = _xorCache.size() + 1 - MAX_CACHED_XOR;
|
||||
if (toRemove > 0) {
|
||||
Set keys = new HashSet(toRemove);
|
||||
// this removes essentially random keys - we dont maintain any sort
|
||||
// of LRU or age. perhaps we should?
|
||||
int removed = 0;
|
||||
for (Iterator iter = _xorCache.keySet().iterator(); iter.hasNext() && removed < toRemove; removed++)
|
||||
keys.add(iter.next());
|
||||
for (Iterator iter = keys.iterator(); iter.hasNext(); )
|
||||
_xorCache.remove(iter.next());
|
||||
}
|
||||
distance = DataHelper.xor(key.getData(), getData());
|
||||
_xorCache.put(key, (Object) distance);
|
||||
cached = _xorCache.size();
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
// explicit buffer, since the compiler can't guess how long it'll be
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("miss [").append(cached).append("] from ");
|
||||
buf.append(DataHelper.toHexString(getData())).append(" to ");
|
||||
buf.append(DataHelper.toHexString(key.getData()));
|
||||
_log.debug(buf.toString(), new Exception());
|
||||
}
|
||||
} else {
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
// explicit buffer, since the compiler can't guess how long it'll be
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("hit from ");
|
||||
buf.append(DataHelper.toHexString(getData())).append(" to ");
|
||||
buf.append(DataHelper.toHexString(key.getData()));
|
||||
_log.debug(buf.toString());
|
||||
}
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
public void clearXorCache() {
|
||||
_xorCache = null;
|
||||
}
|
||||
|
||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||
_data = new byte[HASH_LENGTH];
|
||||
_stringified = null;
|
||||
@@ -189,98 +106,4 @@ public class Hash extends DataStructureImpl {
|
||||
}
|
||||
return _base64ed;
|
||||
}
|
||||
|
||||
/********
|
||||
public static void main(String args[]) {
|
||||
testFill();
|
||||
testOverflow();
|
||||
testFillCheck();
|
||||
}
|
||||
|
||||
private static void testFill() {
|
||||
Hash local = new Hash(new byte[HASH_LENGTH]); // all zeroes
|
||||
local.prepareCache();
|
||||
for (int i = 0; i < MAX_CACHED_XOR; i++) {
|
||||
byte t[] = new byte[HASH_LENGTH];
|
||||
for (int j = 0; j < HASH_LENGTH; j++)
|
||||
t[j] = (byte)((i >> j) & 0xFF);
|
||||
Hash cur = new Hash(t);
|
||||
local.cachedXor(cur);
|
||||
if (local._xorCache.size() != i+1) {
|
||||
_log.error("xor cache size where i=" + i + " isn't correct! size = "
|
||||
+ local._xorCache.size());
|
||||
return;
|
||||
}
|
||||
}
|
||||
_log.debug("Fill test passed");
|
||||
}
|
||||
private static void testOverflow() {
|
||||
Hash local = new Hash(new byte[HASH_LENGTH]); // all zeroes
|
||||
local.prepareCache();
|
||||
for (int i = 0; i < MAX_CACHED_XOR*2; i++) {
|
||||
byte t[] = new byte[HASH_LENGTH];
|
||||
for (int j = 0; j < HASH_LENGTH; j++)
|
||||
t[j] = (byte)((i >> j) & 0xFF);
|
||||
Hash cur = new Hash(t);
|
||||
local.cachedXor(cur);
|
||||
if (i < MAX_CACHED_XOR) {
|
||||
if (local._xorCache.size() != i+1) {
|
||||
_log.error("xor cache size where i=" + i + " isn't correct! size = "
|
||||
+ local._xorCache.size());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (local._xorCache.size() > MAX_CACHED_XOR) {
|
||||
_log.error("xor cache size where i=" + i + " isn't correct! size = "
|
||||
+ local._xorCache.size());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
_log.debug("overflow test passed");
|
||||
}
|
||||
private static void testFillCheck() {
|
||||
Set hashes = new HashSet();
|
||||
Hash local = new Hash(new byte[HASH_LENGTH]); // all zeroes
|
||||
local.prepareCache();
|
||||
// fill 'er up
|
||||
for (int i = 0; i < MAX_CACHED_XOR; i++) {
|
||||
byte t[] = new byte[HASH_LENGTH];
|
||||
for (int j = 0; j < HASH_LENGTH; j++)
|
||||
t[j] = (byte)((i >> j) & 0xFF);
|
||||
Hash cur = new Hash(t);
|
||||
hashes.add(cur);
|
||||
local.cachedXor(cur);
|
||||
if (local._xorCache.size() != i+1) {
|
||||
_log.error("xor cache size where i=" + i + " isn't correct! size = "
|
||||
+ local._xorCache.size());
|
||||
return;
|
||||
}
|
||||
}
|
||||
// now lets recheck using those same hash objects
|
||||
// and see if they're cached
|
||||
for (Iterator iter = hashes.iterator(); iter.hasNext(); ) {
|
||||
Hash cur = (Hash)iter.next();
|
||||
if (!local._xorCache.containsKey(cur)) {
|
||||
_log.error("checking the cache, we dont have "
|
||||
+ DataHelper.toHexString(cur.getData()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// now lets recheck with new objects but the same values
|
||||
// and see if they'return cached
|
||||
for (int i = 0; i < MAX_CACHED_XOR; i++) {
|
||||
byte t[] = new byte[HASH_LENGTH];
|
||||
for (int j = 0; j < HASH_LENGTH; j++)
|
||||
t[j] = (byte)((i >> j) & 0xFF);
|
||||
Hash cur = new Hash(t);
|
||||
if (!local._xorCache.containsKey(cur)) {
|
||||
_log.error("checking the cache, we do NOT have "
|
||||
+ DataHelper.toHexString(cur.getData()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
_log.debug("Fill check test passed");
|
||||
}
|
||||
*********/
|
||||
}
|
||||
|
||||
@@ -30,11 +30,6 @@ public class Lease extends DataStructureImpl {
|
||||
private int _numFailure;
|
||||
|
||||
public Lease() {
|
||||
setGateway(null);
|
||||
setTunnelId(null);
|
||||
setEndDate(null);
|
||||
setNumSuccess(0);
|
||||
setNumFailure(0);
|
||||
}
|
||||
|
||||
/** Retrieve the router at which the destination can be contacted
|
||||
|
||||
@@ -78,18 +78,8 @@ public class LeaseSet extends DataStructureImpl {
|
||||
public final static int MAX_LEASES = 6;
|
||||
|
||||
public LeaseSet() {
|
||||
setDestination(null);
|
||||
setEncryptionKey(null);
|
||||
setSigningKey(null);
|
||||
setSignature(null);
|
||||
setRoutingKey(null);
|
||||
_leases = new ArrayList(MAX_LEASES);
|
||||
_routingKeyGenMod = null;
|
||||
_receivedAsPublished = false;
|
||||
_firstExpiration = Long.MAX_VALUE;
|
||||
_lastExpiration = 0;
|
||||
_decrypted = false;
|
||||
_checked = false;
|
||||
}
|
||||
|
||||
public Destination getDestination() {
|
||||
|
||||
@@ -27,8 +27,6 @@ public class Payload extends DataStructureImpl {
|
||||
private byte[] _unencryptedData;
|
||||
|
||||
public Payload() {
|
||||
setUnencryptedData(null);
|
||||
setEncryptedData(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,8 +28,8 @@ public class PrivateKey extends DataStructureImpl {
|
||||
public final static int KEYSIZE_BYTES = 256;
|
||||
|
||||
public PrivateKey() {
|
||||
setData(null);
|
||||
}
|
||||
|
||||
public PrivateKey(byte data[]) { setData(data); }
|
||||
|
||||
/** constructs from base64
|
||||
@@ -37,7 +37,6 @@ public class PrivateKey extends DataStructureImpl {
|
||||
* on a prior instance of PrivateKey
|
||||
*/
|
||||
public PrivateKey(String base64Data) throws DataFormatException {
|
||||
this();
|
||||
fromBase64(base64Data);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ public class PublicKey extends DataStructureImpl {
|
||||
public final static int KEYSIZE_BYTES = 256;
|
||||
|
||||
public PublicKey() {
|
||||
setData(null);
|
||||
}
|
||||
|
||||
public PublicKey(byte data[]) {
|
||||
if ( (data == null) || (data.length != KEYSIZE_BYTES) )
|
||||
throw new IllegalArgumentException("Data must be specified, and the correct size");
|
||||
@@ -39,7 +39,6 @@ public class PublicKey extends DataStructureImpl {
|
||||
* on a prior instance of PublicKey
|
||||
*/
|
||||
public PublicKey(String base64Data) throws DataFormatException {
|
||||
this();
|
||||
fromBase64(base64Data);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,6 @@ public class RouterAddress extends DataStructureImpl {
|
||||
|
||||
public RouterAddress() {
|
||||
setCost(-1);
|
||||
setExpiration(null);
|
||||
setTransportStyle(null);
|
||||
setOptions(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,10 +31,6 @@ public class RouterIdentity extends DataStructureImpl {
|
||||
private Hash __calculatedHash;
|
||||
|
||||
public RouterIdentity() {
|
||||
setCertificate(null);
|
||||
setSigningPublicKey(null);
|
||||
setPublicKey(null);
|
||||
__calculatedHash = null;
|
||||
}
|
||||
|
||||
public Certificate getCertificate() {
|
||||
|
||||
@@ -60,18 +60,9 @@ public class RouterInfo extends DataStructureImpl {
|
||||
public static final String BW_CAPABILITY_CHARS = "KLMNO";
|
||||
|
||||
public RouterInfo() {
|
||||
setIdentity(null);
|
||||
setPublished(0);
|
||||
_addresses = new HashSet(2);
|
||||
_peers = new HashSet(0);
|
||||
_options = new OrderedProperties();
|
||||
setSignature(null);
|
||||
_validated = false;
|
||||
_isValid = false;
|
||||
_currentRoutingKey = null;
|
||||
_stringified = null;
|
||||
_byteified = null;
|
||||
_hashCodeInitialized = false;
|
||||
}
|
||||
|
||||
public RouterInfo(RouterInfo old) {
|
||||
|
||||
@@ -27,8 +27,8 @@ public class SessionKey extends DataStructureImpl {
|
||||
public static final SessionKey INVALID_KEY = new SessionKey(new byte[KEYSIZE_BYTES]);
|
||||
|
||||
public SessionKey() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public SessionKey(byte data[]) {
|
||||
setData(data);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ public class Signature extends DataStructureImpl {
|
||||
FAKE_SIGNATURE[i] = 0x00;
|
||||
}
|
||||
|
||||
public Signature() { this(null); }
|
||||
public Signature() {}
|
||||
|
||||
public Signature(byte data[]) { setData(data); }
|
||||
|
||||
public byte[] getData() {
|
||||
|
||||
@@ -28,7 +28,8 @@ public class SigningPrivateKey extends DataStructureImpl {
|
||||
|
||||
public final static int KEYSIZE_BYTES = 20;
|
||||
|
||||
public SigningPrivateKey() { this((byte[])null); }
|
||||
public SigningPrivateKey() {}
|
||||
|
||||
public SigningPrivateKey(byte data[]) { setData(data); }
|
||||
|
||||
/** constructs from base64
|
||||
@@ -36,7 +37,6 @@ public class SigningPrivateKey extends DataStructureImpl {
|
||||
* on a prior instance of SigningPrivateKey
|
||||
*/
|
||||
public SigningPrivateKey(String base64Data) throws DataFormatException {
|
||||
this();
|
||||
fromBase64(base64Data);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ public class SigningPublicKey extends DataStructureImpl {
|
||||
|
||||
public final static int KEYSIZE_BYTES = 128;
|
||||
|
||||
public SigningPublicKey() { this((byte[])null); }
|
||||
public SigningPublicKey() {}
|
||||
|
||||
public SigningPublicKey(byte data[]) { setData(data); }
|
||||
|
||||
/** constructs from base64
|
||||
@@ -34,7 +35,6 @@ public class SigningPublicKey extends DataStructureImpl {
|
||||
* on a prior instance of SigningPublicKey
|
||||
*/
|
||||
public SigningPublicKey(String base64Data) throws DataFormatException {
|
||||
this();
|
||||
fromBase64(base64Data);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ public class AbuseReason extends DataStructureImpl {
|
||||
private String _reason;
|
||||
|
||||
public AbuseReason() {
|
||||
setReason(null);
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
|
||||
@@ -33,10 +33,6 @@ public class CreateLeaseSetMessage extends I2CPMessageImpl {
|
||||
private PrivateKey _privateKey;
|
||||
|
||||
public CreateLeaseSetMessage() {
|
||||
setSessionId(null);
|
||||
setLeaseSet(null);
|
||||
setSigningPrivateKey(null);
|
||||
setPrivateKey(null);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
|
||||
@@ -27,7 +27,6 @@ public class DestroySessionMessage extends I2CPMessageImpl {
|
||||
private SessionId _sessionId;
|
||||
|
||||
public DestroySessionMessage() {
|
||||
setSessionId(null);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
|
||||
@@ -27,7 +27,6 @@ public class DisconnectMessage extends I2CPMessageImpl {
|
||||
private String _reason;
|
||||
|
||||
public DisconnectMessage() {
|
||||
setReason(null);
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
|
||||
@@ -31,7 +31,6 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
|
||||
public MessagePayloadMessage() {
|
||||
setSessionId(-1);
|
||||
setMessageId(-1);
|
||||
setPayload(null);
|
||||
}
|
||||
|
||||
public long getSessionId() {
|
||||
|
||||
@@ -28,8 +28,6 @@ public class ReconfigureSessionMessage extends I2CPMessageImpl {
|
||||
private SessionConfig _sessionConfig;
|
||||
|
||||
public ReconfigureSessionMessage() {
|
||||
_sessionId = null;
|
||||
_sessionConfig = null;
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
|
||||
@@ -30,10 +30,6 @@ public class ReportAbuseMessage extends I2CPMessageImpl {
|
||||
private MessageId _messageId;
|
||||
|
||||
public ReportAbuseMessage() {
|
||||
setSessionId(null);
|
||||
setSeverity(null);
|
||||
setReason(null);
|
||||
setMessageId(null);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
|
||||
@@ -34,9 +34,7 @@ public class RequestLeaseSetMessage extends I2CPMessageImpl {
|
||||
private Date _end;
|
||||
|
||||
public RequestLeaseSetMessage() {
|
||||
setSessionId(null);
|
||||
_endpoints = new ArrayList();
|
||||
setEndDate(null);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
|
||||
@@ -34,7 +34,6 @@ public class SendMessageExpiresMessage extends SendMessageMessage {
|
||||
|
||||
public SendMessageExpiresMessage() {
|
||||
super();
|
||||
setExpiration(null);
|
||||
}
|
||||
|
||||
public Date getExpiration() {
|
||||
|
||||
@@ -32,10 +32,6 @@ public class SendMessageMessage extends I2CPMessageImpl {
|
||||
private long _nonce;
|
||||
|
||||
public SendMessageMessage() {
|
||||
setSessionId(null);
|
||||
setDestination(null);
|
||||
setPayload(null);
|
||||
setNonce(0);
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
|
||||
@@ -51,9 +51,7 @@ public class SessionConfig extends DataStructureImpl {
|
||||
}
|
||||
public SessionConfig(Destination dest) {
|
||||
_destination = dest;
|
||||
_signature = null;
|
||||
_creationDate = new Date(Clock.getInstance().now());
|
||||
_options = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,6 @@ public class SessionStatusMessage extends I2CPMessageImpl {
|
||||
public final static int STATUS_INVALID = 3;
|
||||
|
||||
public SessionStatusMessage() {
|
||||
setSessionId(null);
|
||||
setStatus(STATUS_INVALID);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@ public class Frequency {
|
||||
|
||||
public Frequency(long period) {
|
||||
setPeriod(period);
|
||||
setLastEvent(0);
|
||||
setAverageInterval(0);
|
||||
setMinAverageInterval(0);
|
||||
}
|
||||
|
||||
/** how long is this frequency averaged over? */
|
||||
|
||||
@@ -120,18 +120,6 @@ public class Rate {
|
||||
*/
|
||||
public Rate(long period) throws IllegalArgumentException {
|
||||
if (period <= 0) throw new IllegalArgumentException("The period must be strictly positive");
|
||||
_currentTotalValue = 0.0d;
|
||||
_currentEventCount = 0;
|
||||
_currentTotalEventTime = 0;
|
||||
_lastTotalValue = 0.0d;
|
||||
_lastEventCount = 0;
|
||||
_lastTotalEventTime = 0;
|
||||
_extremeTotalValue = 0.0d;
|
||||
_extremeEventCount = 0;
|
||||
_extremeTotalEventTime = 0;
|
||||
_lifetimeTotalValue = 0.0d;
|
||||
_lifetimeEventCount = 0;
|
||||
_lifetimeTotalEventTime = 0;
|
||||
|
||||
_creationDate = now();
|
||||
_lastCoalesceDate = _creationDate;
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.i2p.data.ByteArray;
|
||||
*
|
||||
* Heap size control - survey of usage (April 2010) :
|
||||
*
|
||||
* </pre>
|
||||
* <pre>
|
||||
Size Max MaxMem From
|
||||
|
||||
16 16 256 CryptixAESEngine
|
||||
|
||||
@@ -625,4 +625,12 @@ public class LogManager {
|
||||
shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for LogRecordFormatter
|
||||
* @since 0.7.14
|
||||
*/
|
||||
I2PAppContext getContext() {
|
||||
return _context;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Date;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
|
||||
/**
|
||||
* Render a log record according to the log manager's settings
|
||||
*
|
||||
@@ -44,7 +46,7 @@ class LogRecordFormatter {
|
||||
buf.append(getThread(rec));
|
||||
break;
|
||||
case LogManager.PRIORITY:
|
||||
buf.append(getPriority(rec));
|
||||
buf.append(getPriority(rec, manager.getContext()));
|
||||
break;
|
||||
case LogManager.MESSAGE:
|
||||
buf.append(getWhat(rec));
|
||||
@@ -78,10 +80,23 @@ class LogRecordFormatter {
|
||||
return manager.getDateFormat().format(new Date(logRecord.getDate()));
|
||||
}
|
||||
|
||||
/** don't translate */
|
||||
private static String getPriority(LogRecord rec) {
|
||||
return toString(Log.toLevelString(rec.getPriority()), MAX_PRIORITY_LENGTH);
|
||||
}
|
||||
|
||||
private static final String BUNDLE_NAME = "net.i2p.router.web.messages";
|
||||
|
||||
/** translate @since 0.7.14 */
|
||||
private static String getPriority(LogRecord rec, I2PAppContext ctx) {
|
||||
int len;
|
||||
if (Translate.getLanguage(ctx).equals("de"))
|
||||
len = 8; // KRITISCH
|
||||
else
|
||||
len = MAX_PRIORITY_LENGTH;
|
||||
return toString(Translate.getString(Log.toLevelString(rec.getPriority()), ctx, BUNDLE_NAME), len);
|
||||
}
|
||||
|
||||
private static String getWhat(LogRecord rec) {
|
||||
return rec.getMessage();
|
||||
}
|
||||
@@ -92,6 +107,7 @@ class LogRecordFormatter {
|
||||
return toString(src, MAX_WHERE_LENGTH);
|
||||
}
|
||||
|
||||
/** truncates or pads to the specified size */
|
||||
private static String toString(String str, int size) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (str == null) str = "";
|
||||
@@ -101,4 +117,4 @@ class LogRecordFormatter {
|
||||
buf.append(' ');
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user