moving some System.out statements to use the Java logger plus some other minor tweaks

This commit is contained in:
rj.keller%beonex.com 2005-06-05 15:25:04 +00:00
Родитель 4bf29e19cd
Коммит 8b59b1adbb
5 изменённых файлов: 23 добавлений и 735 удалений

Просмотреть файл

@ -17,16 +17,19 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*/
package calypso.util;
import java.util.logging.*;
/** A class for counting in a variety of bases.
*/
public class Abacus
{
private static final Logger logger = Logger.getLogger("calypso.util.Abacus");
/************************************************
* Formatting Strings
@ -261,11 +264,11 @@ public class Abacus
public static void PadPrint(String aString, int aWidth)
{
System.out.print(aString);
logger.info(aString);
int padCount=aWidth-aString.length();
if(padCount>0)
for(int i=0;i<padCount;i++)
System.out.print(" ");
logger.info(" ");
}
@ -273,9 +276,7 @@ public class Abacus
{
int index=0;
System.out.println(" ");
System.out.println("Value Hex Roman Series Binary Spoken ");
System.out.println("-----------------------------------------------------------------------------");
logger.info(" \nValue Hex Roman Series Binary Spoken \n-----------------------------------------------------------------------------");
for(index=1002;index<1205;index++)
{
PadPrint(index,8);
@ -284,7 +285,7 @@ public class Abacus
PadPrint(Abacus.getSeriesString(index,"ABCD",0,4),10);
PadPrint(Abacus.getBinaryString(index),16);
PadPrint(Abacus.getSpokenString(index),10);
System.out.println("");
logger.info("");
}
}

Просмотреть файл

@ -1,114 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
package calypso.util;
import java.lang.Runtime;
/**
* A utility class to help track memory usage during development.
* The interface is simple. Just create the monitor, do your business,
* and then invoke the done method. <p>
*
* The figure for the ammount of memory allocated should be accurate
* but the number for the ammount of garbage can be off by quite a bit
* if any garbage collection was done between the monitor's creation
* and the call to done. <p>
*
* Currently, it just prints some stuff to the console. I'd like to
* extend it so it creates a window and displays it's info in that.
*
* @author Thom FillABomb :-)
*/
public class MemoryMonitor
{
Runtime fSystem;
long fFreeAtStart,
fFreeAtEnd,
fGarbageGenerated;
String fUserString = null;
public MemoryMonitor (String monitorDescription)
{
fUserString = monitorDescription;
initialize();
}
public MemoryMonitor ()
{
initialize();
}
protected void initialize ()
{
fSystem = Runtime.getRuntime();
beginMonitor();
}
public void done ()
{
finishMonitor ();
System.out.println();
if (fUserString != null)
System.out.println (fUserString);
System.out.println (" Starting Free: " + fFreeAtStart);
System.out.println (" Ending Free: " + fFreeAtEnd);
System.out.println (" Memory Delta: " + (fFreeAtStart - fFreeAtEnd));
System.out.println ("Garbage Generated: " + fGarbageGenerated);
}
protected void freeUpMemory ()
{
// we might want to tickle Kipp's memory Manager here as well...
fSystem.runFinalization();
// might want to sleep here
fSystem.gc();
fSystem.gc();
}
void beginMonitor ()
{
freeUpMemory();
fFreeAtStart = fSystem.freeMemory();
}
void finishMonitor ()
{
long totalUsed, minusGarbage;
totalUsed = fSystem.freeMemory();
freeUpMemory();
minusGarbage = fSystem.freeMemory();
// it would also be interesting to purge the recyclers here and
// see how much memory they're occupying
fGarbageGenerated = minusGarbage - totalUsed;
fFreeAtEnd = minusGarbage;
}
}

Просмотреть файл

@ -1,111 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Jamie Zawinski <jwz@netscape.com>, 29 Aug 1997.
*/
package grendel.mime;
import java.io.RandomAccessFile;
import java.io.IOException;
import calypso.util.ByteBuf;
import grendel.mime.parser.MimeParserFactory;
import grendel.mime.html.MimeHTMLOperatorFactory;
/* This silly little class implements an operator which draws every MIME
part as a labelled box, to give an overview of the MIME structure (and
incidentally to show that all of the operators are closed properly,
since the table won't show up if they're not.)
*/
class MimeDebugOperator implements IMimeOperator {
String type;
public MimeDebugOperator(IMimeObject obj) {
type = obj.contentType();
System.out.print("<P><TABLE BORDER CELLPADDING=8 CELLSPACING=4" +
(obj.headers() == null ? "" : " WIDTH=100%") +
">");
System.out.print("<TR><TH BGCOLOR=BLACK><FONT COLOR=#FFFFFF>" +
type +
(obj.partID() == null ? "" :
"<BR>" + obj.partID()) +
"</FONT></TH></TR>");
System.out.print("<TR><TD ALIGN=CENTER VALIGN=CENTER BGCOLOR=#FFFFFF>\n");
}
public void pushBytes(ByteBuf b) { }
public IMimeOperator createChild(IMimeObject object) {
return new MimeDebugOperator(object);
}
public void pushEOF() {
System.out.println("</TD></TR></TABLE><P><!-- " + this.type + " -->");
}
}
class TestMime {
public static void main(String args[]) {
for (int i = 0; i < args.length; i++) {
try {
System.err.println("Starting...");
long start = System.currentTimeMillis();
RandomAccessFile file = new RandomAccessFile(args[i], "r");
String toplevel_type = "message/rfc822";
IMimeParser parser = MimeParserFactory.Make(toplevel_type);
IMimeOperator op;
if (true)
op = MimeHTMLOperatorFactory.Make(parser.getObject());
else
op = new MimeDebugOperator(parser.getObject());
parser.setOperator(op);
byte[] bytes = new byte[1024];
ByteBuf buf = new ByteBuf(bytes.length);
int bread;
do {
bread = file.read(bytes, 0, bytes.length);
if (bread > 0) {
buf.setLength(0);
buf.append(bytes, 0, bread); // this sucks!
parser.pushBytes(buf);
}
} while (bread >= 0);
bytes = null;
buf = null;
parser.pushEOF();
long end = System.currentTimeMillis();
System.err.println("Took " + (end - start) + " milliseconds.");
} catch (IOException e) {
System.err.println("Got an IO exception: " + e.getMessage());
e.printStackTrace();
return;
}
}
}
}

Просмотреть файл

@ -1,488 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* ParseBerkeleyFolder.java
* Created: Terry Weissman <terry@netscape.com>, 8 Aug 1997.
* Shamelessly based on mbox.c which was
* Created: Jamie Zawinski <jwz@netscape.com>, 22 Jul 1997.
*/
/**
This sectionizes a mailbox file into its component messages; it understands
both the BSD and Solaris formats ("From " and "Content-Length".) See also
http://www.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html
for related ranting.
*/
package grendel.storage;
import grendel.storage.intertwingle.Twingle;
import calypso.util.Assert;
import calypso.util.ByteBuf;
import calypso.util.ByteLineBuffer;
import calypso.util.RandomAccessFileWithByteLines;
import javax.mail.internet.InternetHeaders;
import java.io.RandomAccessFile;
import java.io.InputStream;
import java.io.IOException;
class ParseBerkeleyFolder {
static final boolean DEBUG = false;
static final int CONTENT_LENGTH_SLACK = 100;
Twingle twingle = Twingle.GetSingleton();
/* Returns the file-byte-index of the end of the message, if it can be
determined from the given Content-Length, and if it checks out.
If the Content-Length is obvious nonsense, or if any read/seek errors
occur, returns IT_SEEK_ERROR.
The file-read-pointer is expected to be just past the headers of the
message in question (poised to read the first byte of the body.)
It will be left in that same place upon return.
The Content-Length is checked for sanity (by examining the file at
the indicated position) and is adjusted if it seems to be off by a
small amount. It can be off by up to N bytes in either direction;
the correct value is assumed to be the closer of the two nearest
message-delimiters within that range (either earlier or later.)
*/
BerkeleyFolder fFolder;
byte buf[] = new byte [CONTENT_LENGTH_SLACK * 2 + 1];
protected int total_message_count = 0;
protected int undeleted_message_count = 0;
protected int unread_message_count = 0;
protected long deleted_message_bytes = 0;
int totalMessageCount() { return total_message_count; }
int undeletedMessageCount() { return undeleted_message_count; }
int unreadMessageCount() { return unread_message_count; }
long deletedMessageBytes() { return deleted_message_bytes; }
int find_content_end(RandomAccessFileWithByteLines in, int content_length,
int file_length)
throws IOException {
int start_pos = (int) in.getFilePointer();
boolean eof = false;
int read_start, read_end, target;
int early_match, late_match;
int bytes;
int result = -1;
Assert.Assertion(content_length >= 0 && start_pos >= 0);
if (content_length < 0 || start_pos < 0) return -1;
target = start_pos + content_length;
read_start = target - ((buf.length - 1) / 2);
/* Read a block centered on the position indicated by Content-Length
(with `slack' bytes in either direction.) */
int b = 0;
int bytes_left = buf.length - 1;
if (read_start < start_pos) {
bytes_left -= (start_pos - read_start);
read_start = start_pos;
}
if (read_start + bytes_left > file_length) {
bytes_left = file_length - read_start;
eof = true;
}
in.seek(read_start);
in.readFully(buf, b, bytes_left);
// System.err.println(new String(buf, b, bytes_left));
b += bytes_left;
read_end = read_start + b;
/* Find the first mailbox delimiter at or before the position indicated
by Content-Length.
*/
early_match = -1;
int s = (target - read_start) + 6;
if (s > (read_end - read_start))
s = (read_end - read_start);
s -= 6;
for (; s > 0; s--) {
if (buf[s] == '\n' &&
buf[s+1] == 'F' &&
buf[s+2] == 'r' &&
buf[s+3] == 'o' &&
buf[s+4] == 'm' &&
buf[s+5] == ' ') {
early_match = read_start + s;
}
}
/* Find the first mailbox delimiter at or past the position indicated
by Content-Length. */
late_match = -1;
if (read_end > target) {
s = (target - read_start) - 6;
if (s < 0) s = 0;
for ( ;
s < (read_end - read_start) - 6;
s++) {
if (buf[s] == '\n' &&
buf[s+1] == 'F' &&
buf[s+2] == 'r' &&
buf[s+3] == 'o' &&
buf[s+4] == 'm' &&
buf[s+5] == ' ') {
late_match = read_start + s;
break;
}
}
}
if (late_match == -1 && eof) {
/* EOF counts as a match. */
late_match = file_length - 1;
}
if (early_match == late_match) {
if (late_match < target) {
late_match = -1;
} else {
early_match = -1;
}
} else if (early_match == -1 && late_match < target) {
early_match = late_match;
late_match = -1;
}
if (early_match >= 0 && late_match >= 0) {
/* Found two -- pick the closest one. */
if ((target - early_match) < (late_match - target)) {
result = early_match;
} else {
result = late_match;
}
}
else if (early_match >= 0) {
result = early_match;
} else {
result = late_match;
}
if (DEBUG) {
if (result == -1)
System.err.println("content-length of " + content_length + " is nonsense (or off by more than " + CONTENT_LENGTH_SLACK + " bytes)");
else if (result != target) {
if (result == late_match)
System.err.println("content-length of " + content_length +
" was " +
(late_match - target) +
" bytes too small (pos " +
result +
")");
else
System.err.println("content-length of " + content_length +
" was " +
(target - early_match) +
" bytes too large (pos " +
result +
")");
} else {
System.err.println("*** Hey; Content-Length worked perfectly!");
}
}
in.seek(start_pos);
return result;
}
void recordOne(int envelope_start, int message_start,
int headers_end, int message_end,
InternetHeaders headers)
throws IOException {
Assert.Assertion(envelope_start >= 0 &&
message_start > envelope_start &&
headers_end >= message_start &&
message_end >= headers_end);
if (DEBUG) {
System.out.println("Found one: start: " + message_start +
"; end: " + message_end);
// headers.dump();
}
BerkeleyMessage m = new BerkeleyMessage(fFolder, headers);
total_message_count++;
if (m.isDeleted()) {
deleted_message_bytes += (message_end - message_start);
} else {
undeleted_message_count++;
if (!m.isRead())
unread_message_count++;
}
m.setStorageFolderIndex(message_start);
m.setSize(message_end - message_start);
fFolder.noticeInitialMessage(m);
if (twingle != null) {
if (DEBUG) System.out.println("Calling twingle.add");
twingle.add(headers, fFolder);
}
}
void mapOverMessages(RandomAccessFile infile, BerkeleyFolder f)
throws IOException {
mapOverMessages(infile, f, 0);
}
protected synchronized void mapOverMessages(RandomAccessFile infile,
BerkeleyFolder f,
long starting_file_pos)
throws IOException {
fFolder = f;
InternetHeaders hdrs = new InternetHeaders();
int file_length = (int) infile.length();
infile.seek(starting_file_pos);
RandomAccessFileWithByteLines in =
new RandomAccessFileWithByteLines(infile);
ByteBuf line = ByteBuf.Alloc();
InternetHeaders headers = new InternetHeaders();
int last_end = 0;
int start = -1;
int headers_end = -1;
boolean inheader = false;
ByteBuf contentlengthname = new ByteBuf("Content-Length");
ByteBuf lenstr = new ByteBuf();
int last_position = 0; // file byte index of start of prev line
int this_position = 0; // file byte index of start of this line
int next_position = 0; // file byte index of start of next line
boolean last_blank_p = false; // whether the prev line was blank
boolean this_blank_p = false; // whether this line is blank
while (in.readLine(line)) {
last_position = this_position;
this_position = next_position;
next_position = (int) in.getFilePointer();
byte[] bytes = line.toBytes(); // doesn't cons
last_blank_p = this_blank_p;
this_blank_p = (line.length() == 0);
if (line.length() >= 5 &&
bytes[0] == 'F' &&
bytes[1] == 'r' &&
bytes[2] == 'o' &&
bytes[3] == 'm' &&
bytes[4] == ' ') {
if (start >= 0) {
// The last byte of the previous message is the byte before the
// first character on the current "From " line; unless the
// previous line was blank, in which case, the last byte of the
// previous message is the byte before the first byte on that
// line. This seems to do the right thing most of the time, in
// the face of missing or slightly-off Content-Length headers.
//
int end = (last_blank_p
? last_position
: this_position);
recordOne(last_end, start, headers_end, end, headers);
last_end = end;
}
// The following message begins at the first byte of the next line
// following this "From " line (that is, the byte after this line's
// linebreak character(s).)
//
start = next_position;
headers = new InternetHeaders();
inheader = true;
continue;
}
if (inheader) {
if (line.length() == 0 ||
line.byteAt(0) == '\n' || line.byteAt(0) == '\r') {
inheader = false;
headers_end = this_position;
String hh[] = headers.getHeader("Content-Length");
if (hh != null && hh.length != 0) {
int contentLength;
try {
contentLength = Integer.parseInt(hh[0]);
} catch (NumberFormatException e) {
contentLength = -1;
}
if (contentLength > 0) {
int loc = find_content_end(in, contentLength, file_length);
if (loc > 0) {
this_position = loc;
next_position = loc;
this_blank_p = false;
in.seek(loc);
}
}
}
} else {
headers.addHeaderLine(line.toString());
}
}
}
if (start >= 0 && !inheader) {
if (headers_end <= start)
headers_end = file_length;
recordOne(last_end, start, headers_end, file_length, headers);
}
}
/** Overwrite the X-Mozilla-Status header near the given file position.
@param message_start The position in the file of the start of a
message. A header block is assumed to start at
this position. The file is scanned forward for
an X-Mozilla-Status header in this block.
@param message_length The length of the message in bytes.
@param mozilla_flags The flags to overwrite into the existing
X-Mozilla-Status header, if any.
@return true if the header was overwritten, false
otherwise.
*/
boolean flushMozillaStatus(RandomAccessFile io,
long message_start,
int message_length,
short mozilla_flags) throws IOException {
long message_end = message_start + message_length;
io.seek(message_start);
ByteBuf buf = null;
ByteBuf line = null;
try {
buf = ByteBuf.Alloc();
line = ByteBuf.Alloc();
ByteLineBuffer linebuf = new ByteLineBuffer();
boolean eof = false;
// `pos' will point at the file position of the beginning of the
// line we are processing.
long pos = message_start;
while (!eof) {
buf.setLength(0);
eof = (buf.read(io, 1024) < 0);
if (eof) {
linebuf.pushEOF();
} else {
linebuf.pushBytes(buf);
}
while (linebuf.pullLine(line)) {
byte first = line.byteAt(0);
if (first == '\r' || first == '\n')
// end of headers -- and we never saw X-Mozilla-Status!
return false;
else if ((first == 'X' || first == 'x') &&
(line.regionMatches(true, 0, "X-Mozilla-Status:", 0, 17))) {
// Woo hoo. Make sure it has exactly the right number of bytes.
int start = 17;
while (line.byteAt(start) == ' ' || line.byteAt(start) == '\t')
start++;
for (int digits = 0; digits < 4; digits++) {
byte b = line.byteAt(start + digits);
if (! ((b >= '0' && b <= '9') ||
(b >= 'a' && b <= 'f') ||
(b >= 'A' && b <= 'F')))
// if there aren't 4 consecutive hex digits, bug out.
return false;
}
// If there isn't whitespace or a newline after the digits,
// bug out.
if (line.byteAt(start + 4) > ' ')
return false;
// Ok! At this point, `start' points to the position in the
// line of the first hex digit. So the position in the file
// is `pos+start'. Seek there, and overwrite the bytes with
// the new flag.
String s = Integer.toHexString(((int) mozilla_flags) & 0xFFFF);
if (s.length() == 3) s = "0" + s;
else if (s.length() == 2) s = "00" + s;
else if (s.length() == 1) s = "000" + s;
io.seek(pos + start);
io.write(s.getBytes());
return true; // all done!
}
pos += line.length();
if (pos > message_end)
// oops, reached end of message before end of headers?
return false;
}
}
} finally {
if (buf != null) ByteBuf.Recycle(buf);
if (line != null) ByteBuf.Recycle(line);
}
// reached eof before end of message headers.
return false;
}
}

Просмотреть файл

@ -79,65 +79,65 @@ public class ActionFactory {
static Runnable fComposeMessageThread = new DummyComposeMessageThread();
static public ExitAction GetExitAction() {
public static ExitAction GetExitAction() {
return fExitAction;
}
static public NewMailAction GetNewMailAction() {
public static NewMailAction GetNewMailAction() {
return fNewMailAction;
}
static public ComposeMessageAction GetComposeMessageAction() {
public static ComposeMessageAction GetComposeMessageAction() {
return fComposeMessageAction;
}
static public void SetComposeMessageThread(Runnable aThread) {
public static void SetComposeMessageThread(Runnable aThread) {
fComposeMessageThread = aThread;
}
static public void setIdent(int aIdent) {
public static void setIdent(int aIdent) {
System.out.println("setIdent "+aIdent);
fIdent = aIdent;
}
static public int getIdent() {
public static int getIdent() {
System.out.println("getIdent "+fIdent);
return fIdent;
}
static public PreferencesAction GetPreferencesAction() {
public static PreferencesAction GetPreferencesAction() {
return fPrefsAction;
}
static public SearchAction GetSearchAction() {
public static SearchAction GetSearchAction() {
return fSearchAction;
}
static public RunFiltersAction GetRunFiltersAction() {
public static RunFiltersAction GetRunFiltersAction() {
return fRunFiltersAction;
}
static public ShowTooltipsAction GetShowTooltipsAction() {
public static ShowTooltipsAction GetShowTooltipsAction() {
return fShowTooltipsAction;
}
static public RunIdentityPrefsAction GetRunIdentityPrefsAction() {
public static RunIdentityPrefsAction GetRunIdentityPrefsAction() {
return fRunIdentityPrefsAction;
}
static public RunServerPrefsAction GetRunServerPrefsAction() {
public static RunServerPrefsAction GetRunServerPrefsAction() {
return fRunServerPrefsAction;
}
static public RunGeneralPrefsAction GetRunGeneralPrefsAction() {
public static RunGeneralPrefsAction GetRunGeneralPrefsAction() {
return fRunGeneralPrefsAction;
}
static public RunUIPrefsAction GetRunUIPrefsAction() {
public static RunUIPrefsAction GetRunUIPrefsAction() {
return fRunUIPrefsAction;
}
static public ShowAddressBookAction GetShowAddressBookAction() {
public static ShowAddressBookAction GetShowAddressBookAction() {
return fShowAddressBookAction;
}