more efficient mem alloc & usage

This commit is contained in:
jrandom
2004-07-25 23:33:54 +00:00
committed by zzz
parent ce3e7e623c
commit abaa5d87f6
3 changed files with 15 additions and 16 deletions

View File

@ -14,7 +14,7 @@ import java.io.ByteArrayOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import net.i2p.I2PAppContext;
@ -61,7 +61,7 @@ public class AESInputStream extends FilterInputStream {
_lastBlock = new byte[BLOCK_SIZE];
System.arraycopy(iv, 0, _lastBlock, 0, BLOCK_SIZE);
_encryptedBuf = new ByteArrayOutputStream(BLOCK_SIZE);
_readyBuf = new LinkedList();
_readyBuf = new ArrayList(1024);
_cumulativePaddingStripped = 0;
_eofFound = false;
}

View File

@ -349,8 +349,7 @@ public class Rate {
}
}
public void store(OutputStream out, String prefix) throws IOException {
StringBuffer buf = new StringBuffer(16*1048);
public void store(String prefix, StringBuffer buf) throws IOException {
PersistenceHelper.add(buf, prefix, ".period", "Number of milliseconds in the period", _period);
PersistenceHelper.add(buf, prefix, ".creationDate",
"When was this rate created? (milliseconds since the epoch, GMT)", _creationDate);
@ -388,7 +387,6 @@ public class Rate {
PersistenceHelper.add(buf, prefix, ".lifetimeTotalEventTime",
"How many milliseconds have the events since this stat was created consumed?",
_lifetimeTotalEventTime);
out.write(buf.toString().getBytes());
}
/**
@ -476,11 +474,11 @@ public class Rate {
rate.addData(i * 100, 20);
}
rate.coallesce();
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(2048);
StringBuffer buf = new StringBuffer(1024);
try {
rate.store(baos, "rate.test");
byte data[] = baos.toByteArray();
_log.error("Stored rate: size = " + data.length + "\n" + new String(data));
rate.store("rate.test", buf);
byte data[] = buf.toString().getBytes();
_log.error("Stored rate: size = " + data.length + "\n" + buf.toString());
Properties props = new Properties();
props.load(new java.io.ByteArrayInputStream(data));

View File

@ -110,16 +110,17 @@ public class RateStat {
buf.append("# ").append(_description).append(NL);
buf.append("# ").append(NL).append(NL);
out.write(buf.toString().getBytes());
buf = null;
buf.setLength(0);
for (int i = 0; i < _rates.length; i++) {
StringBuffer rbuf = new StringBuffer(1024);
rbuf.append("#######").append(NL);
rbuf.append("# Period : ").append(DataHelper.formatDuration(_rates[i].getPeriod())).append(" for rate ")
buf.append("#######").append(NL);
buf.append("# Period : ").append(DataHelper.formatDuration(_rates[i].getPeriod())).append(" for rate ")
.append(_groupName).append(" - ").append(_statName).append(NL);
rbuf.append(NL);
out.write(rbuf.toString().getBytes());
buf.append(NL);
out.write(buf.toString().getBytes());
String curPrefix = prefix + "." + DataHelper.formatDuration(_rates[i].getPeriod());
_rates[i].store(out, curPrefix);
_rates[i].store(curPrefix, buf);
out.write(buf.toString().getBytes());
buf.setLength(0);
}
}