[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/manager/io SocketConnectionFacade.ja
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-03-02 23:16:00
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29560/src/java/net/sf/asterisk/manager/io Added Files: SocketConnectionFacade.java SocketConnectionFacadeImpl.java Log Message: Added unit tests for ManagerReader and ManagerWriter (and did some refactoring to make this work) --- NEW FILE: SocketConnectionFacade.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.manager.io; import java.io.IOException; public interface SocketConnectionFacade { String readLine() throws IOException; void print(String s) throws IOException; void flush() throws IOException; void close() throws IOException; } --- NEW FILE: SocketConnectionFacadeImpl.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.manager.io; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket; public class SocketConnectionFacadeImpl implements SocketConnectionFacade { private final Socket socket; private final BufferedReader reader; private final PrintWriter writer; public SocketConnectionFacadeImpl(String host, int port) throws IOException { this.socket = new Socket(host, port); this.reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); this.writer = new PrintWriter(new OutputStreamWriter(this.socket.getOutputStream())); } public String readLine() throws IOException { return reader.readLine(); } public void print(String s) throws IOException { writer.print(s); } public void flush() throws IOException { writer.flush(); } public void close() throws IOException { this.socket.close(); } } |