?? ftpwriter.java
字號:
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package server.ftp;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.net.Socket;
import util.Message;
/**
* Writer object used by the server. It has the spying capability.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class FtpWriter extends Writer {
private OutputStreamWriter mOriginalWriter;
private SpyConnectionInterface mSpy;
private FtpConfig mConfig;
/**
* Constructor - set the actual writer object
*/
public FtpWriter(Socket soc, FtpConfig config) throws IOException {
mOriginalWriter = new OutputStreamWriter(soc.getOutputStream());
mConfig = config;
}
/**
* Get the spy object to get what the user is writing.
*/
public SpyConnectionInterface getSpyObject() {
return mSpy;
}
/**
* Set the connection spy object.
*/
public void setSpyObject(SpyConnectionInterface spy) {
mSpy = spy;
}
/**
* Spy print. Monitor server response.
*/
private void spyResponse(final String str) throws IOException {
final SpyConnectionInterface spy = mSpy;
if (spy != null) {
Message msg = new Message() {
public void execute() {
try {
spy.response(str);
}
catch(Exception ex) {
mSpy = null;
mConfig.getLogger().error(ex);
}
}
};
mConfig.getMessageQueue().add(msg);
}
}
/**
* Write a character array.
*/
public void write(char[] cbuf) throws IOException {
String str = new String(cbuf);
spyResponse(str);
mOriginalWriter.write(cbuf);
mOriginalWriter.flush();
}
/**
* Write a portion of character array
*/
public void write(char[] cbuf, int off, int len) throws IOException {
String str = new String(cbuf, off, len);
spyResponse(str);
mOriginalWriter.write(cbuf, off, len);
mOriginalWriter.flush();
}
/**
* Write a single character
*/
public void write(int c) throws IOException {
String str = "" + (char)c;
spyResponse(str);
mOriginalWriter.write(c);
mOriginalWriter.flush();
}
/**
* Write a string
*/
public void write(String str) throws IOException {
spyResponse(str);
mOriginalWriter.write(str);
mOriginalWriter.flush();
}
/**
* Write a portion of the string.
*/
public void write(String str, int off, int len) throws IOException {
String strpart = str.substring(off, len);
spyResponse(strpart);
mOriginalWriter.write(str, off, len);
mOriginalWriter.flush();
}
/**
* Close writer.
*/
public void close() throws IOException {
mOriginalWriter.close();
}
/**
* Flush the stream
*/
public void flush() throws IOException {
mOriginalWriter.flush();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -