}else if(uline.startsWith("FILTER:")) {
line = line.substring("FILTER:".length()).trim();
outsb.append("Here is the result:\r\n");
final String content = readLines(reader, false);
final Bucket input = new ArrayBucket(content.getBytes("UTF-8"));
final Bucket output = new ArrayBucket();
InputStream inputStream = null;
OutputStream outputStream = null;
InputStream bis = null;
try {
inputStream = input.getInputStream();
outputStream = output.getOutputStream();
ContentFilter.filter(inputStream, outputStream, "text/html", new URI("http://127.0.0.1:8888/"), null, null, null, core.getLinkFilterExceptionProvider());
inputStream.close();
inputStream = null;
outputStream.close();
outputStream = null;
bis = output.getInputStream();
while(bis.available() > 0){
outsb.append((char)bis.read());
}
} catch (IOException e) {
outsb.append("Bucket error?: " + e.getMessage());
Logger.error(this, "Bucket error?: " + e, e);
} catch (URISyntaxException e) {
outsb.append("Internal error: " + e.getMessage());
Logger.error(this, "Internal error: " + e, e);
} finally {
Closer.close(inputStream);
Closer.close(outputStream);
Closer.close(bis);
input.free();
output.free();
}
outsb.append("\r\n");
}else if(uline.startsWith("BLOW")) {
n.getNodeUpdater().blow("caught an IOException : (Incompetent Operator) :p", true);
outsb.append("\r\n");
w.write(outsb.toString());
w.flush();
return false;
} else if(uline.startsWith("SHUTDOWN")) {
StringBuilder sb = new StringBuilder();
sb.append("Shutting node down.\r\n");
w.write(sb.toString());
w.flush();
n.exit("Shutdown from console");
} else if(uline.startsWith("RESTART")) {
StringBuilder sb = new StringBuilder();
sb.append("Restarting the node.\r\n");
w.write(sb.toString());
w.flush();
n.getNodeStarter().restart();
} else if(uline.startsWith("QUIT") && (core.directTMCI == this)) {
StringBuilder sb = new StringBuilder();
sb.append("QUIT command not available in console mode.\r\n");
w.write(sb.toString());
w.flush();
return false;
} else if(uline.startsWith("QUIT")) {
StringBuilder sb = new StringBuilder();
sb.append("Closing connection.\r\n");
w.write(sb.toString());
w.flush();
return true;
} else if(uline.startsWith("MEMSTAT")) {
Runtime rt = Runtime.getRuntime();
float freeMemory = rt.freeMemory();
float totalMemory = rt.totalMemory();
float maxMemory = rt.maxMemory();
long usedJavaMem = (long)(totalMemory - freeMemory);
long allocatedJavaMem = (long)totalMemory;
long maxJavaMem = (long)maxMemory;
int availableCpus = rt.availableProcessors();
NumberFormat thousendPoint = NumberFormat.getInstance();
ThreadGroup tg = Thread.currentThread().getThreadGroup();
while(tg.getParent() != null) tg = tg.getParent();
int threadCount = tg.activeCount();
StringBuilder sb = new StringBuilder();
sb.append("Used Java memory:\u00a0" + SizeUtil.formatSize(usedJavaMem, true)+"\r\n");
sb.append("Allocated Java memory:\u00a0" + SizeUtil.formatSize(allocatedJavaMem, true)+"\r\n");
sb.append("Maximum Java memory:\u00a0" + SizeUtil.formatSize(maxJavaMem, true)+"\r\n");
sb.append("Running threads:\u00a0" + thousendPoint.format(threadCount)+"\r\n");
sb.append("Available CPUs:\u00a0" + availableCpus+"\r\n");
sb.append("Java Version:\u00a0" + System.getProperty("java.version")+"\r\n");
sb.append("JVM Vendor:\u00a0" + System.getProperty("java.vendor")+"\r\n");
sb.append("JVM Version:\u00a0" + System.getProperty("java.version")+"\r\n");
sb.append("OS Name:\u00a0" + System.getProperty("os.name")+"\r\n");
sb.append("OS Version:\u00a0" + System.getProperty("os.version")+"\r\n");
sb.append("OS Architecture:\u00a0" + System.getProperty("os.arch")+"\r\n");
w.write(sb.toString());
w.flush();
return false;
} else if(uline.startsWith("HELP")) {
printHeader(w);
outsb.append("\r\n");
w.write(outsb.toString());
w.flush();
return false;
} else if(uline.startsWith("PUT:") || (getCHKOnly = uline.startsWith("GETCHK:"))) {
if(getCHKOnly)
line = line.substring(("GETCHK:").length()).trim();
else
line = line.substring("PUT:".length()).trim();
String content;
if(line.length() > 0) {
// Single line insert
content = line;
} else {
// Multiple line insert
content = readLines(reader, false);
}
// Insert
byte[] data = content.getBytes(ENCODING);
InsertBlock block = new InsertBlock(new ArrayBucket(data), null, FreenetURI.EMPTY_CHK_URI);
FreenetURI uri;
try {
uri = client.insert(block, getCHKOnly, null);
} catch (InsertException e) {