Author: alessio.soldano(a)jboss.com
Date: 2013-02-01 18:42:03 -0500 (Fri, 01 Feb 2013)
New Revision: 482
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/utils/JBossLoggingOutputStream.java
Modified:
core/trunk/core/pom.xml
core/trunk/pom.xml
Log:
Sorting dependencies a bit and adding JBoss Logging flavor of Logging Output Stream
Modified: core/trunk/core/pom.xml
===================================================================
--- core/trunk/core/pom.xml 2013-02-01 18:48:53 UTC (rev 481)
+++ core/trunk/core/pom.xml 2013-02-01 23:42:03 UTC (rev 482)
@@ -50,11 +50,21 @@
</dependency>
<dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-common-core</artifactId>
</dependency>
<dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.ws</groupId>
<artifactId>jbossws-common</artifactId>
</dependency>
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/utils/JBossLoggingOutputStream.java
===================================================================
--- core/trunk/core/src/main/java/org/jboss/wise/core/utils/JBossLoggingOutputStream.java
(rev 0)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/utils/JBossLoggingOutputStream.java 2013-02-01
23:42:03 UTC (rev 482)
@@ -0,0 +1,88 @@
+package org.jboss.wise.core.utils;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.jboss.logging.Logger;
+import org.jboss.logging.Logger.Level;
+
+public class JBossLoggingOutputStream extends OutputStream {
+
+ public static final int DEFAULT_BUFFER_LENGTH = 2048;
+
+ protected boolean hasBeenClosed = false;
+ protected byte[] buf;
+ protected int count;
+ private int bufLength;
+ protected Logger logger;
+ protected Level level;
+
+ public JBossLoggingOutputStream(Logger log, Level level) throws
IllegalArgumentException {
+ if (log == null) {
+ throw new IllegalArgumentException("Null category!");
+ }
+ if (level == null) {
+ throw new IllegalArgumentException("Null priority!");
+ }
+ this.level = level;
+ logger = log;
+ bufLength = DEFAULT_BUFFER_LENGTH;
+ buf = new byte[DEFAULT_BUFFER_LENGTH];
+ count = 0;
+ }
+
+ public void close() {
+ flush();
+ hasBeenClosed = true;
+ }
+
+ public void write(final int b) throws IOException {
+ if (hasBeenClosed) {
+ throw new IOException("The stream has been closed.");
+ }
+ // would this be writing past the buffer?
+ if (count == bufLength) {
+ // grow the buffer
+ final int newBufLength = bufLength + DEFAULT_BUFFER_LENGTH;
+ final byte[] newBuf = new byte[newBufLength];
+ System.arraycopy(buf, 0, newBuf, 0, bufLength);
+ buf = newBuf;
+ bufLength = newBufLength;
+ }
+ buf[count] = (byte) b;
+ count++;
+ }
+
+ public void flush() {
+ if (count == 0) {
+ return;
+ }
+ // don't print out blank lines; flushing from PrintStream puts
+ // out these
+ // For linux system
+ if (count == 1 && ((char) buf[0]) == '\n') {
+ reset();
+ return;
+ }
+ // For mac system
+ if (count == 1 && ((char) buf[0]) == '\r') {
+ reset();
+ return;
+ }
+ // On windows system
+ if (count == 2 && (char) buf[0] == '\r' && (char) buf[1] ==
'\n') {
+ reset();
+ return;
+ }
+ final byte[] theBytes = new byte[count];
+ System.arraycopy(buf, 0, theBytes, 0, count);
+ logger.log(level, new String(theBytes));
+ reset();
+ }
+
+ private void reset() {
+ // not resetting the buffer -- assuming that if it grew then it
+ // will likely grow similarly again
+ count = 0;
+ }
+}
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2013-02-01 18:48:53 UTC (rev 481)
+++ core/trunk/pom.xml 2013-02-01 23:42:03 UTC (rev 482)
@@ -121,13 +121,32 @@
<version>1.4</version>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ </dependency>
+
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-common-core</artifactId>
<version>2.2.17.GA</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </exclusion>
+ </exclusions>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging</artifactId>
+ <version>3.1.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
<groupId>org.jboss.ws</groupId>
<artifactId>jbossws-common</artifactId>
Show replies by date