public class SocketWriter
extends java.lang.Thread
SocketWriter writer = null; try { writer = new SocketWriter(file, port, Helper.DEFAULT_SOCKET_TIMEOUT); } catch (Throwable t) { String host = InetAddress.getLocalHost().getHostName(); throw new ConnectException("Socket connection to " + host + ":" + port + " refused"); } if (writer != null) { String host = InetAddress.getLocalHost().getHostName(); try { writer.start(); server.getBySocket(aoSession, name, host, port); writer.join(); } catch (Throwable ttt) { ttt.printStackTrace(); } Throwable t = writer.getThrowable(); if (t != null) { if (t instanceof FileNotFoundException) { throw (FileNotFoundException) t; } else { throw (IOException) t; } } writer.close(); }
Modifier and Type | Field and Description |
---|---|
protected int |
bufSize |
protected java.net.Socket |
client |
static int |
DEFAULT_BUFSIZE
The default buffer size is 100000.
|
static int |
DEFAULT_PORT
The default port number is 11011.
|
protected java.lang.Throwable |
error |
protected java.io.File |
file |
static java.lang.Object |
ID |
protected java.net.ServerSocket |
serverSocket |
protected int |
timeout |
Constructor and Description |
---|
SocketWriter(java.io.File file,
int timeout)
Write the given file to socket with default portnumber (11011) and default
buffersize (100000).
|
SocketWriter(java.io.File file,
int port,
int timeout)
Write the given file to socket using the given portnumber and default
buffersize (10000).
|
SocketWriter(java.io.File file,
int port,
int bufSize,
int timeout)
Write the given file to socket using the given portnumber and buffersize.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close all open sockes, if necessary.
|
java.lang.Throwable |
getThrowable()
Get the exception that may be occurred during running method.
|
static void |
receive(CORBAFileServerIF server,
AoSession aoSession,
int port,
java.lang.String name,
java.io.File file)
Receive the given file to the server.
|
void |
run()
Start the transaction.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public static final int DEFAULT_BUFSIZE
public static final int DEFAULT_PORT
public static java.lang.Object ID
protected java.net.ServerSocket serverSocket
protected int timeout
protected java.net.Socket client
protected java.io.File file
protected java.lang.Throwable error
protected int bufSize
public SocketWriter(java.io.File file, int timeout) throws java.net.UnknownHostException, java.io.IOException
file
- The file to be transmitted.timeout
- the socket timeout in millisseconds.java.net.UnknownHostException
java.io.IOException
public SocketWriter(java.io.File file, int port, int timeout) throws java.net.UnknownHostException, java.io.IOException
file
- The file to be transmitted.port
- the port number to be used.timeout
- teh socket timeout in millisseconds.java.net.UnknownHostException
java.io.IOException
public SocketWriter(java.io.File file, int port, int bufSize, int timeout) throws java.net.UnknownHostException, java.io.IOException
file
- The file to be transmitted.port
- the port number to be used.bufsize
- the buffer size to be used.timeout
- teh socket timeout in millisseconds.java.net.UnknownHostException
java.io.IOException
public java.lang.Throwable getThrowable()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
getThrowable()
public void close()
public static void receive(CORBAFileServerIF server, AoSession aoSession, int port, java.lang.String name, java.io.File file) throws java.net.UnknownHostException, java.io.FileNotFoundException, java.net.ConnectException, java.lang.InterruptedException, java.io.IOException, CORBAFileServerException
server
- The CORABFileServer instanceaoSession
- the ASAM ODS session for the secerity check.port
- the port to used.name
- the name of the file on server side.file
- the file to be sent.java.net.UnknownHostException
java.io.FileNotFoundException
java.net.ConnectException
java.lang.InterruptedException
java.io.IOException
CORBAFileServerException