diff options
Diffstat (limited to 'gcc-4.4.3/libjava/classpath/gnu/classpath/debug')
8 files changed, 925 insertions, 0 deletions
diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/Component.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/Component.java new file mode 100644 index 000000000..dce257502 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/Component.java @@ -0,0 +1,175 @@ +/* Component.java -- a component log level. + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under terms +of your choice, provided that you also meet, for each linked independent +module, the terms and conditions of the license of that module. An +independent module is a module which is not derived from or based on +this library. If you modify this library, you may extend this exception +to your version of the library, but you are not obligated to do so. If +you do not wish to do so, delete this exception statement from your +version. */ + + +package gnu.classpath.debug; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.logging.Level; + +public final class Component extends Level +{ + + /* + * HOW TO ADD NEW COMPONENTS: + * + * If you want to add a new, simple component, that you will use in + * logging statements, simply create a new class variable that + * instantiates this class, and choose an appropriate string name + * and a integer constant not used by any other component level. + * + * For example, if my component had to do with 'frobbing', I would + * add this entry below: + * + * private static final Component FROBBING = new Component ("FROBBING", 7); + * + * Then, I would update the component 'EVERYTHING' to have and end + * index ONE GREATER THAN the index of the new component. + * + * ADDING NEW COMPONENT CLASSES: + * + * A "component class" is a run of more than one component, which can + * be enabled all at once. EVERYTHING and SSL are examples of component + * classes. To add a new class, create a new component with a start index + * equal to the index of the first member component, and with an end + * index equal to the index of the last member component plus one. + */ + + /** + * Signifies that everything should be logged. This should be used to + * enable or disable levels only; logging code should not use it. + */ + public static final Component EVERYTHING = new Component ("*", 0, 11); + + /** + * Signifies that all SSL related messages should be logged. This should + * be used to enable or disable levels only; logging code should not use + * it. + */ + public static final Component SSL = new Component ("SSL", 0, 5); + + /** + * Traces the progression of an SSL handshake. + */ + public static final Component SSL_HANDSHAKE = new Component ("SSL HANDSHAKE", 0); + + /** + * Traces record layer messages during SSL communications. + */ + public static final Component SSL_RECORD_LAYER = new Component ("SSL RECORD LAYER", 1); + + /** + * Trace details about the SSL key exchange. + */ + public static final Component SSL_KEY_EXCHANGE = new Component ("SSL KEY EXCHANGE", 2); + + /** + * Trace running of delegated tasks. + */ + public static final Component SSL_DELEGATED_TASK = new Component ("SSL DELEGATED TASK", 3); + + /* Index 4 reserved for future use by SSL components. */ + + /** + * Trace the operation of cryptographic primitives. + */ + public static final Component CRYPTO = new Component ("CRYPTO", 5); + + /** + * Trace the parsing of X.509 certificates and related objects. + */ + public static final Component X509 = new Component ("X.509", 6); + + /** + * Trace access control policies, including the parsing of + * java.policy files. + */ + public static final Component POLICY = new Component ("POLICY", 7); + + /** + * Trace ipp implementation. + */ + public static final Component IPP = new Component ("IPP", 10); + + private final int startIndex; + private final int endIndex; + + private Component (final String name, final int bitIndex) + { + this (name, bitIndex, bitIndex + 1); + } + + private Component (final String name, final int startIndex, final int endIndex) + { + super (name, Level.FINE.intValue ()); + this.startIndex = startIndex; + this.endIndex = endIndex; + } + + /** + * Return the component for the given name. + * + * @param name The name of the component to get. + * @return The named component, or null if there is no such component. + */ + public static Component forName (final String name) + { + try + { + Field f = Component.class.getField (name.toUpperCase ()); + if (!Modifier.isStatic (f.getModifiers ()) + || Component.class.isAssignableFrom (f.getClass ())) + return null; + return (Component) f.get (null); + } + catch (Throwable _) + { + return null; + } + } + + public int startIndex () + { + return startIndex; + } + + public int endIndex () + { + return endIndex; + } +}
\ No newline at end of file diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/PreciseFilter.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/PreciseFilter.java new file mode 100644 index 000000000..7b88b2c8c --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/PreciseFilter.java @@ -0,0 +1,105 @@ +/* PreciseFilter.java -- filter log messages by precise level. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under terms +of your choice, provided that you also meet, for each linked independent +module, the terms and conditions of the license of that module. An +independent module is a module which is not derived from or based on +this library. If you modify this library, you may extend this exception +to your version of the library, but you are not obligated to do so. If +you do not wish to do so, delete this exception statement from your +version. */ + + +package gnu.classpath.debug; + +import java.util.BitSet; +import java.util.logging.Filter; +import java.util.logging.LogRecord; + +public final class PreciseFilter implements Filter +{ + + /** + * The singleton filter instance. + */ + public static final PreciseFilter GLOBAL = new PreciseFilter (); + + private final BitSet enabled; + + private PreciseFilter () + { + enabled = new BitSet (); + } + + /** + * Disable logging of a component. + * + * @param component The component to disable logging for. + * @throws NullPointerException If component is null. + */ + public void disable (final Component component) + { + enabled.clear (component.startIndex (), component.endIndex ()); + } + + /** + * Enable logging of a component. + * + * @param component The component to enable logging for. + * @throws NullPointerException If component is null. + */ + public void enable (final Component component) + { + enabled.set (component.startIndex (), component.endIndex ()); + } + + /** + * Tell if a component is enabled for logging. + * + * @param component The component to test. + * @return True iff the specified component is enabled for logging. + * @throws NullPointerException If component is null. + */ + public boolean isEnabled (final Component component) + { + return (enabled.get (component.startIndex ())); + } + + public boolean isLoggable (final LogRecord record) + { + try + { + return isEnabled ((Component) record.getLevel ()); + } + catch (ClassCastException cce) + { + return true; + } + } +}
\ No newline at end of file diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/Simple1LineFormatter.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/Simple1LineFormatter.java new file mode 100644 index 000000000..96573193a --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/Simple1LineFormatter.java @@ -0,0 +1,161 @@ +/* Simple1LineFormatter.java -- A simple 1-line logging formatter + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.debug; + +import gnu.java.security.action.GetPropertyAction; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.security.AccessController; +import java.text.DateFormat; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +/** + * A simple 1-line formatter to use instead of the 2-line SimpleFormatter used + * by default in the JDK logging handlers. + * <p> + * The fixed format of this formatter is as follows: + * <p> + * <ol> + * <li>Date: As a yyyy-MM-dd string.</li> + * <li>Time: As a HH:mm:ss.SSSS Z string.</li> + * <li>Thread identifier, right-justified, and framed in an 11-digit field.</li> + * <li>Class name, without its package name, left-justified, and framed in a + * 32-character field.</li> + * <li>Method name, left-justified, and framed in a 32-character field.</li> + * <li>Level name, left-justified, and framed in a 6-character field.</li> + * <li>User message and arguments.</li> + * <li>Platform-dependent line-separator.</li> + * <li>Optionally, if the log-record contains a thrown exception, that + * exception's stack trace is appended to the output.</li> + * </ol> + * <p> + * Here is an example of the output generated by this formatter: + * <p> + * <pre> + * 2006-02-27 21:59:12.0881 +1100 -1343151280 EncodedKeyFactory engineGeneratePublic() FINER - ENTRY java.security.spec.X509EncodedKeySpec@b00d7fc0 + * 2006-02-27 21:59:12.0887 +1100 -1343151280 EncodedKeyFactory engineGeneratePublic() FINE - Exception in DSSPublicKey.valueOf(). Ignore + * java.security.InvalidParameterException: Unexpected OID: 1.2.840.113549.1.1.1 + * at gnu.java.security.key.dss.DSSKeyPairX509Codec.decodePublicKey (DSSKeyPairX509Codec.java:205) + * at gnu.java.security.key.dss.DSSPublicKey.valueOf (DSSPublicKey.java:136) + * at gnu.java.security.jce.sig.EncodedKeyFactory.engineGeneratePublic (EncodedKeyFactory.java:218) + * at java.security.KeyFactory.generatePublic (KeyFactory.java:219) + * at gnu.java.security.x509.X509Certificate.parse (X509Certificate.java:657) + * at gnu.java.security.x509.X509Certificate.<init> (X509Certificate.java:163) + * ... + * 2006-02-27 21:59:12.0895 +1100 -1343151280 RSAKeyPairX509Codec decodePublicKey() FINER - ENTRY [B@b00d7fd0 + * 2006-02-27 21:59:12.0897 +1100 -1343151280 RSAKeyPairX509Codec decodePublicKey() FINER - RETURN gnu.java.security.key.rsa.GnuRSAPublicKey@b00fb940 + * </pre> + */ +public class Simple1LineFormatter + extends Formatter +{ + private static final String DAT_PATTERN = "yyyy-MM-dd HH:mm:ss.SSSS Z "; + private static final String THREAD_PATTERN = " #########0;-#########0"; + private static final String SPACES_32 = " "; + private static final String SPACES_6 = " "; + private static final String LS = (String) AccessController.doPrivileged + (new GetPropertyAction("line.separator")); + private DateFormat dateFormat; + private NumberFormat threadFormat; + + // default 0-arguments constructor + + public String format(LogRecord record) + { + if (dateFormat == null) + dateFormat = new SimpleDateFormat(DAT_PATTERN); + + if (threadFormat == null) + threadFormat = new DecimalFormat(THREAD_PATTERN); + + StringBuilder sb = new StringBuilder(180) + .append(dateFormat.format(new Date(record.getMillis()))) + .append(threadFormat.format(record.getThreadID())) + .append(" "); + String s = record.getSourceClassName(); + if (s == null) + sb.append(SPACES_32); + else + { + s = s.trim(); + int i = s.lastIndexOf("."); + if (i != - 1) + s = s.substring(i + 1); + + s = (s + SPACES_32).substring(0, 32); + } + + sb.append(s).append(" "); + s = record.getSourceMethodName(); + if (s == null) + sb.append(SPACES_32); + else + { + s = s.trim(); + if (s.endsWith("()")) + s = (s.trim() + SPACES_32).substring(0, 32); + else + s = (s.trim() + "()" + SPACES_32).substring(0, 32); + } + + sb.append(s).append(" "); + s = String.valueOf(record.getLevel()); + if (s == null) + sb.append(SPACES_6); + else + s = (s.trim() + SPACES_6).substring(0, 6); + + sb.append(s).append(" - ").append(formatMessage(record)).append(LS); + Throwable cause = record.getThrown(); + if (cause != null) + { + StringWriter sw = new StringWriter(); + cause.printStackTrace(new PrintWriter(sw, true)); + sb.append(sw.toString()); + } + + return sb.toString(); + } +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/SystemLogger.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/SystemLogger.java new file mode 100644 index 000000000..8919e80c7 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/SystemLogger.java @@ -0,0 +1,102 @@ +/* SystemLogger.java -- Classpath's system debugging logger. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under terms +of your choice, provided that you also meet, for each linked independent +module, the terms and conditions of the license of that module. An +independent module is a module which is not derived from or based on +this library. If you modify this library, you may extend this exception +to your version of the library, but you are not obligated to do so. If +you do not wish to do so, delete this exception statement from your +version. */ + + +package gnu.classpath.debug; + +import gnu.java.security.action.GetPropertyAction; + +import java.security.AccessController; +import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; + +public final class SystemLogger extends Logger +{ + public static final SystemLogger SYSTEM = new SystemLogger(); + + static + { + SYSTEM.setFilter (PreciseFilter.GLOBAL); + String defaults = (String) AccessController.doPrivileged + (new GetPropertyAction("gnu.classpath.debug.components")); + + if (defaults != null) + { + StringTokenizer tok = new StringTokenizer (defaults, ","); + while (tok.hasMoreTokens ()) + { + Component c = Component.forName (tok.nextToken ()); + if (c != null) + PreciseFilter.GLOBAL.enable (c); + SYSTEM.log (Level.INFO, "enabled: {0}", c); + } + } + } + + /** + * Fetch the system logger instance. The logger returned is meant for debug + * and diagnostic logging for Classpath internals. + * + * @return The system logger. + */ + public static SystemLogger getSystemLogger() + { + // XXX Check some permission here? + return SYSTEM; + } + + /** + * Keep only one instance of the system logger. + */ + private SystemLogger() + { + super("gnu.classpath", null); + } + + /** + * Variable-arguments log method. + * + * @param level The level to log to. + * @param format The format string. + * @param args The arguments. + */ + public void logv(Level level, String format, Object... args) + { + log(level, format, args); + } +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeInputStream.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeInputStream.java new file mode 100644 index 000000000..ef6b2ed3d --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeInputStream.java @@ -0,0 +1,98 @@ +/* TeeInputStream.java + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under terms +of your choice, provided that you also meet, for each linked independent +module, the terms and conditions of the license of that module. An +independent module is a module which is not derived from or based on +this library. If you modify this library, you may extend this exception +to your version of the library, but you are not obligated to do so. If +you do not wish to do so, delete this exception statement from your +version. */ + +package gnu.classpath.debug; + +import java.io.*; + +/** + * An input stream that copies all its input to a byte sink. + * + * @author Chris Burdess + */ +public class TeeInputStream + extends InputStream +{ + + private final InputStream in; + private final OutputStream out; + + /** + * Constructs a tee input stream. + * @param in the underlying input stream + * @param out the output sink + */ + public TeeInputStream(InputStream in, OutputStream out) + { + this.in = in; + this.out = out; + } + + public int read() + throws IOException + { + int ret = in.read(); + out.write(ret); + out.flush(); + return ret; + } + + public int read(byte[] b, int off, int len) + throws IOException + { + int ret = in.read(b, off, len); + if (ret != -1) + { + out.write(b, off, ret); + out.flush(); + } + return ret; + } + + public void close() + throws IOException + { + in.close(); + out.close(); + } + + public final boolean markSupported() + { + return false; + } + +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeOutputStream.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeOutputStream.java new file mode 100644 index 000000000..cff60894a --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeOutputStream.java @@ -0,0 +1,93 @@ +/* TeeOutputStream.java + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under terms +of your choice, provided that you also meet, for each linked independent +module, the terms and conditions of the license of that module. An +independent module is a module which is not derived from or based on +this library. If you modify this library, you may extend this exception +to your version of the library, but you are not obligated to do so. If +you do not wish to do so, delete this exception statement from your +version. */ + +package gnu.classpath.debug; + +import java.io.*; + +/** + * An output stream that copies all its output to an additional byte sink. + * + * @author Chris Burdess + */ +public class TeeOutputStream + extends OutputStream +{ + + private final OutputStream out; + private final OutputStream sink; + + /** + * Constructs a tee output stream. + * @param out the underlying output stream + * @param sink the output sink + */ + public TeeOutputStream(OutputStream out, OutputStream sink) + { + this.out = out; + this.sink = sink; + } + + public void write(int c) + throws IOException + { + out.write(c); + sink.write(c); + } + + public void write(byte[] b, int off, int len) + throws IOException + { + out.write(b, off, len); + sink.write(b, off, len); + } + + public void flush() + throws IOException + { + out.flush(); + sink.flush(); + } + + public void close() + throws IOException + { + out.close(); + sink.close(); + } + +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeReader.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeReader.java new file mode 100644 index 000000000..8fa742e21 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeReader.java @@ -0,0 +1,98 @@ +/* TeeReader.java + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under terms +of your choice, provided that you also meet, for each linked independent +module, the terms and conditions of the license of that module. An +independent module is a module which is not derived from or based on +this library. If you modify this library, you may extend this exception +to your version of the library, but you are not obligated to do so. If +you do not wish to do so, delete this exception statement from your +version. */ + +package gnu.classpath.debug; + +import java.io.*; + +/** + * A reader that copies all characters read to an output sink. + * + * @author Chris Burdess + */ +public class TeeReader + extends Reader +{ + + private final Reader in; + private final Writer out; + + /** + * Constructs a tee reader. + * @param in the input + * @param out the output sink + */ + public TeeReader(Reader in, Writer out) + { + this.in = in; + this.out = out; + } + + public int read() + throws IOException + { + int ret = in.read(); + out.write(ret); + out.flush(); + return ret; + } + + public int read(char[] b, int off, int len) + throws IOException + { + int ret = in.read(b, off, len); + if (ret != -1) + { + out.write(b, off, ret); + out.flush(); + } + return ret; + } + + public void close() + throws IOException + { + in.close(); + out.close(); + } + + public final boolean markSupported() + { + return false; + } + +} diff --git a/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeWriter.java b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeWriter.java new file mode 100644 index 000000000..f226c2165 --- /dev/null +++ b/gcc-4.4.3/libjava/classpath/gnu/classpath/debug/TeeWriter.java @@ -0,0 +1,93 @@ +/* TeeWriter.java + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under terms +of your choice, provided that you also meet, for each linked independent +module, the terms and conditions of the license of that module. An +independent module is a module which is not derived from or based on +this library. If you modify this library, you may extend this exception +to your version of the library, but you are not obligated to do so. If +you do not wish to do so, delete this exception statement from your +version. */ + +package gnu.classpath.debug; + +import java.io.*; + +/** + * A writer that copies all its output to an additional character sink. + * + * @author Chris Burdess + */ +public class TeeWriter + extends Writer +{ + + private final Writer out; + private final Writer sink; + + /** + * Constructs a tee writer. + * @param out the underlying writer + * @param sink the output sink + */ + public TeeWriter(Writer out, Writer sink) + { + this.out = out; + this.sink = sink; + } + + public void write(int c) + throws IOException + { + out.write(c); + sink.write(c); + } + + public void write(char[] b, int off, int len) + throws IOException + { + out.write(b, off, len); + sink.write(b, off, len); + } + + public void flush() + throws IOException + { + out.flush(); + sink.flush(); + } + + public void close() + throws IOException + { + out.close(); + sink.close(); + } + +} |