Handle exceptions better in TerminalPrintStream. (FELIX-2604)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@999076 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java b/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java
index 43e230c..f706396 100644
--- a/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java
+++ b/shell.remote/src/main/java/org/apache/felix/shell/remote/Shell.java
@@ -19,10 +19,10 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.net.Socket;
-import org.apache.felix.service.command.CommandProcessor;
-import org.apache.felix.service.command.CommandSession;
import org.apache.felix.shell.ShellService;
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
/**
* Implements the shell.
diff --git a/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java b/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java
index 430e6d9..3cf2099 100644
--- a/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java
+++ b/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalPrintStream.java
@@ -16,10 +16,8 @@
*/
package org.apache.felix.shell.remote;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
-import java.net.SocketException;
/**
* Class implementing a <tt>TerminalPrintStream</tt>.
@@ -38,45 +36,54 @@
{
super(tout);
m_services = services;
- }//constructor
+ }
public void print(String str)
{
- try
+ if (out != null)
{
- byte[] bytes = str.getBytes();
- out.write(bytes, 0, bytes.length);
- flush();
- }
- catch (Exception ex)
- {
- if (!m_isClosed)
+ try
{
- m_services.error("TerminalPrintStream::print()", ex);
+ byte[] bytes = str.getBytes();
+ out.write(bytes, 0, bytes.length);
+ flush();
+ }
+ catch (Exception ex)
+ {
+ if (!m_isClosed)
+ {
+ m_services.error("TerminalPrintStream::print()", ex);
+ }
}
}
- }//print
+ }
public void println(String str)
{
print(str + "\r\n");
- }//println
+ }
public void flush()
{
- try
+ if (out != null)
{
- out.flush();
+ try
+ {
+ out.flush();
+ }
+ catch (Exception ex)
+ {
+ if (!m_isClosed)
+ {
+ m_services.error("TerminalPrintStream::println()", ex);
+ }
+ }
}
- catch (IOException ex)
- {
- m_services.error("TerminalPrintStream::println()", ex);
- }
- }//flush
+ }
public void close()
{
m_isClosed = true;
super.close();
}
-}//class TerminalPrintStream
+}
\ No newline at end of file
diff --git a/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java b/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java
index 2ba8dd8..d75406e 100644
--- a/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java
+++ b/shell.remote/src/main/java/org/apache/felix/shell/remote/TerminalReader.java
@@ -29,8 +29,8 @@
*/
class TerminalReader extends Reader
{
- protected InputStream m_in;
- protected PrintStream m_out;
+ protected final InputStream m_in;
+ protected final PrintStream m_out;
protected boolean m_echo = false;
protected boolean m_eof = false;
@@ -169,6 +169,7 @@
{
m_in.close();
}//close
+
/**
* <b>Bell</b><br>
* The ANSI defined byte code for the NVT bell.