[jboss-svn-commits] JBoss Common SVN: r3108 - in jboss-logmanager/trunk/src/main/java/org/jboss: logmanager and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Apr 13 11:15:01 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-04-13 11:15:01 -0400 (Mon, 13 Apr 2009)
New Revision: 3108
Added:
jboss-logmanager/trunk/src/main/java/org/jboss/stdio/
jboss-logmanager/trunk/src/main/java/org/jboss/stdio/ContextInputStream.java
jboss-logmanager/trunk/src/main/java/org/jboss/stdio/ContextPrintStream.java
jboss-logmanager/trunk/src/main/java/org/jboss/stdio/Init.java
jboss-logmanager/trunk/src/main/java/org/jboss/stdio/NullInputStream.java
Removed:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ContextPrintStream.java
Log:
Add input stream which can be overridden on a per-thread level; unify input and output stream stuff into one package
Deleted: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ContextPrintStream.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ContextPrintStream.java 2009-04-09 16:47:17 UTC (rev 3107)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ContextPrintStream.java 2009-04-13 15:15:01 UTC (rev 3108)
@@ -1,204 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.logmanager;
-
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.IOException;
-import java.util.Locale;
-
-public final class ContextPrintStream extends PrintStream {
-
- private static final class StreamHolder extends InheritableThreadLocal<PrintStream> {
- private final PrintStream initialValue;
-
- private StreamHolder(final PrintStream initialValue) {
- this.initialValue = initialValue;
- }
-
- protected PrintStream initialValue() {
- return initialValue;
- }
- }
-
- private final ThreadLocal<PrintStream> delegateHolder;
-
- public ContextPrintStream(PrintStream defaultDelegate) {
- super((OutputStream)null);
- delegateHolder = new StreamHolder(defaultDelegate);
- }
-
- public PrintStream swapDelegate(final PrintStream newDelegate) {
- try {
- return delegateHolder.get();
- } finally {
- delegateHolder.set(newDelegate);
- }
- }
-
- public static PrintStream getAndSetContextSystemOut(final PrintStream newSystemOut) {
- return ((ContextPrintStream)System.out).swapDelegate(newSystemOut);
- }
-
- public static PrintStream getAndSetContextSystemErr(final PrintStream newSystemOut) {
- return ((ContextPrintStream)System.err).swapDelegate(newSystemOut);
- }
-
- public static void initSystemStreams(final PrintStream defaultSystemOut, final PrintStream defaultSystemErr) {
- System.setOut(new ContextPrintStream(defaultSystemOut));
- System.setErr(new ContextPrintStream(defaultSystemErr));
- }
-
- public void close() {
- }
-
- public void flush() {
- delegateHolder.get().flush();
- }
-
- public boolean checkError() {
- return false;
- }
-
- public void write(final int b) {
- delegateHolder.get().write(b);
- }
-
- public void write(final byte[] buf, final int off, final int len) {
- delegateHolder.get().write(buf, off, len);
- }
-
- public void print(final boolean b) {
- delegateHolder.get().print(b);
- }
-
- public void print(final char c) {
- delegateHolder.get().print(c);
- }
-
- public void print(final int i) {
- delegateHolder.get().print(i);
- }
-
- public void print(final long l) {
- delegateHolder.get().print(l);
- }
-
- public void print(final float f) {
- delegateHolder.get().print(f);
- }
-
- public void print(final double d) {
- delegateHolder.get().print(d);
- }
-
- public void print(final char[] s) {
- delegateHolder.get().print(s);
- }
-
- public void print(final String s) {
- delegateHolder.get().print(s);
- }
-
- public void print(final Object obj) {
- delegateHolder.get().print(obj);
- }
-
- public void println() {
- delegateHolder.get().println();
- }
-
- public void println(final boolean x) {
- delegateHolder.get().println(x);
- }
-
- public void println(final char x) {
- delegateHolder.get().println(x);
- }
-
- public void println(final int x) {
- delegateHolder.get().println(x);
- }
-
- public void println(final long x) {
- delegateHolder.get().println(x);
- }
-
- public void println(final float x) {
- delegateHolder.get().println(x);
- }
-
- public void println(final double x) {
- delegateHolder.get().println(x);
- }
-
- public void println(final char[] x) {
- delegateHolder.get().println(x);
- }
-
- public void println(final String x) {
- delegateHolder.get().println(x);
- }
-
- public void println(final Object x) {
- delegateHolder.get().println(x);
- }
-
- public PrintStream printf(final String format, final Object... args) {
- return delegateHolder.get().printf(format, args);
- }
-
- public PrintStream printf(final Locale l, final String format, final Object... args) {
- return delegateHolder.get().printf(l, format, args);
- }
-
- public PrintStream format(final String format, final Object... args) {
- return delegateHolder.get().format(format, args);
- }
-
- public PrintStream format(final Locale l, final String format, final Object... args) {
- return delegateHolder.get().format(l, format, args);
- }
-
- public PrintStream append(final CharSequence csq) {
- return delegateHolder.get().append(csq);
- }
-
- public PrintStream append(final CharSequence csq, final int start, final int end) {
- return delegateHolder.get().append(csq, start, end);
- }
-
- public PrintStream append(final char c) {
- return delegateHolder.get().append(c);
- }
-
- public void write(final byte[] b) throws IOException {
- delegateHolder.get().write(b);
- }
-
- public void setError() {
- }
-
- public void clearError() {
- }
-}
Added: jboss-logmanager/trunk/src/main/java/org/jboss/stdio/ContextInputStream.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/stdio/ContextInputStream.java (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/stdio/ContextInputStream.java 2009-04-13 15:15:01 UTC (rev 3108)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stdio;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+public final class ContextInputStream extends InputStream {
+ private static final class StreamHolder extends InheritableThreadLocal<InputStream> {
+ private final InputStream initialValue;
+
+ private StreamHolder(final InputStream initialValue) {
+ this.initialValue = initialValue;
+ }
+
+ protected InputStream initialValue() {
+ return initialValue;
+ }
+ }
+
+ private final ThreadLocal<InputStream> delegateHolder;
+
+ public ContextInputStream(final InputStream defaultDelegate) {
+ delegateHolder = new StreamHolder(defaultDelegate);
+ }
+
+ public InputStream swapDelegate(final InputStream newDelegate) {
+ try {
+ return delegateHolder.get();
+ } finally {
+ delegateHolder.set(newDelegate);
+ }
+ }
+
+ public static InputStream getAndSetSystemIn(final InputStream newSystemIn) {
+ return ((ContextInputStream)System.in).swapDelegate(newSystemIn);
+ }
+
+ private InputStream getDelegate() {
+ return delegateHolder.get();
+ }
+
+ public int read() throws IOException {
+ return getDelegate().read();
+ }
+
+ public int read(final byte[] b) throws IOException {
+ return getDelegate().read(b);
+ }
+
+ public int read(final byte[] b, final int off, final int len) throws IOException {
+ return getDelegate().read(b, off, len);
+ }
+
+ public long skip(final long n) throws IOException {
+ return getDelegate().skip(n);
+ }
+
+ public int available() throws IOException {
+ return getDelegate().available();
+ }
+
+ public void close() throws IOException {
+ getDelegate().close();
+ }
+
+ public void mark(final int readlimit) {
+ getDelegate().mark(readlimit);
+ }
+
+ public void reset() throws IOException {
+ getDelegate().reset();
+ }
+
+ public boolean markSupported() {
+ return getDelegate().markSupported();
+ }
+}
Copied: jboss-logmanager/trunk/src/main/java/org/jboss/stdio/ContextPrintStream.java (from rev 3104, jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ContextPrintStream.java)
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/stdio/ContextPrintStream.java (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/stdio/ContextPrintStream.java 2009-04-13 15:15:01 UTC (rev 3108)
@@ -0,0 +1,200 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stdio;
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.IOException;
+import java.util.Locale;
+
+public final class ContextPrintStream extends PrintStream {
+
+ private static final class StreamHolder extends InheritableThreadLocal<PrintStream> {
+ private final PrintStream initialValue;
+
+ private StreamHolder(final PrintStream initialValue) {
+ this.initialValue = initialValue;
+ }
+
+ protected PrintStream initialValue() {
+ return initialValue;
+ }
+ }
+
+ private final ThreadLocal<PrintStream> delegateHolder;
+
+ public ContextPrintStream(PrintStream defaultDelegate) {
+ super((OutputStream)null);
+ delegateHolder = new StreamHolder(defaultDelegate);
+ }
+
+ public PrintStream swapDelegate(final PrintStream newDelegate) {
+ try {
+ return delegateHolder.get();
+ } finally {
+ delegateHolder.set(newDelegate);
+ }
+ }
+
+ public static PrintStream getAndSetContextSystemOut(final PrintStream newSystemOut) {
+ return ((ContextPrintStream)System.out).swapDelegate(newSystemOut);
+ }
+
+ public static PrintStream getAndSetContextSystemErr(final PrintStream newSystemOut) {
+ return ((ContextPrintStream)System.err).swapDelegate(newSystemOut);
+ }
+
+ public void close() {
+ delegateHolder.get().close();
+ }
+
+ public void flush() {
+ delegateHolder.get().flush();
+ }
+
+ public boolean checkError() {
+ return delegateHolder.get().checkError();
+ }
+
+ public void write(final int b) {
+ delegateHolder.get().write(b);
+ }
+
+ public void write(final byte[] buf, final int off, final int len) {
+ delegateHolder.get().write(buf, off, len);
+ }
+
+ public void print(final boolean b) {
+ delegateHolder.get().print(b);
+ }
+
+ public void print(final char c) {
+ delegateHolder.get().print(c);
+ }
+
+ public void print(final int i) {
+ delegateHolder.get().print(i);
+ }
+
+ public void print(final long l) {
+ delegateHolder.get().print(l);
+ }
+
+ public void print(final float f) {
+ delegateHolder.get().print(f);
+ }
+
+ public void print(final double d) {
+ delegateHolder.get().print(d);
+ }
+
+ public void print(final char[] s) {
+ delegateHolder.get().print(s);
+ }
+
+ public void print(final String s) {
+ delegateHolder.get().print(s);
+ }
+
+ public void print(final Object obj) {
+ delegateHolder.get().print(obj);
+ }
+
+ public void println() {
+ delegateHolder.get().println();
+ }
+
+ public void println(final boolean x) {
+ delegateHolder.get().println(x);
+ }
+
+ public void println(final char x) {
+ delegateHolder.get().println(x);
+ }
+
+ public void println(final int x) {
+ delegateHolder.get().println(x);
+ }
+
+ public void println(final long x) {
+ delegateHolder.get().println(x);
+ }
+
+ public void println(final float x) {
+ delegateHolder.get().println(x);
+ }
+
+ public void println(final double x) {
+ delegateHolder.get().println(x);
+ }
+
+ public void println(final char[] x) {
+ delegateHolder.get().println(x);
+ }
+
+ public void println(final String x) {
+ delegateHolder.get().println(x);
+ }
+
+ public void println(final Object x) {
+ delegateHolder.get().println(x);
+ }
+
+ public PrintStream printf(final String format, final Object... args) {
+ return delegateHolder.get().printf(format, args);
+ }
+
+ public PrintStream printf(final Locale l, final String format, final Object... args) {
+ return delegateHolder.get().printf(l, format, args);
+ }
+
+ public PrintStream format(final String format, final Object... args) {
+ return delegateHolder.get().format(format, args);
+ }
+
+ public PrintStream format(final Locale l, final String format, final Object... args) {
+ return delegateHolder.get().format(l, format, args);
+ }
+
+ public PrintStream append(final CharSequence csq) {
+ return delegateHolder.get().append(csq);
+ }
+
+ public PrintStream append(final CharSequence csq, final int start, final int end) {
+ return delegateHolder.get().append(csq, start, end);
+ }
+
+ public PrintStream append(final char c) {
+ return delegateHolder.get().append(c);
+ }
+
+ public void write(final byte[] b) throws IOException {
+ delegateHolder.get().write(b);
+ }
+
+ protected void setError() {
+ }
+
+ protected void clearError() {
+ }
+}
Added: jboss-logmanager/trunk/src/main/java/org/jboss/stdio/Init.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/stdio/Init.java (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/stdio/Init.java 2009-04-13 15:15:01 UTC (rev 3108)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stdio;
+
+import java.io.PrintStream;
+import java.io.InputStream;
+
+public final class Init {
+ private Init() {}
+
+ public static void initSystemStreams(final PrintStream defaultSystemOut, final PrintStream defaultSystemErr, final InputStream defaultSystemIn) {
+ System.setOut(new ContextPrintStream(defaultSystemOut));
+ System.setErr(new ContextPrintStream(defaultSystemErr));
+ System.setIn(new ContextInputStream(defaultSystemIn));
+ }
+}
Added: jboss-logmanager/trunk/src/main/java/org/jboss/stdio/NullInputStream.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/stdio/NullInputStream.java (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/stdio/NullInputStream.java 2009-04-13 15:15:01 UTC (rev 3108)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.stdio;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+public final class NullInputStream extends InputStream {
+ public int read() throws IOException {
+ return -1;
+ }
+}
More information about the jboss-svn-commits
mailing list