[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi AGIReader.java,NONE,1.1 AGIR
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-03-09 23:33:15
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17393/src/java/net/sf/asterisk/fastagi Added Files: AGIReader.java AGIReaderImpl.java Log Message: Added AGIReader --- NEW FILE: AGIReader.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.fastagi; import java.io.IOException; import net.sf.asterisk.fastagi.reply.AGIReply; /** * The AGIReader reads the replies from the network and parses them using a * ReplyBuilder. * * @author srt * @version $Id: AGIReader.java,v 1.1 2005/03/09 23:33:03 srt Exp $ */ public interface AGIReader { /** * Reads one reply from the network. * * @return the reply read. * @throws IOException if the reply can be read. */ AGIReply readReply() throws IOException; } --- NEW FILE: AGIReaderImpl.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.fastagi; import java.io.IOException; import java.util.ArrayList; import java.util.List; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; /** * Default implementation of the AGIReader implementation. * * @author srt * @version $Id: AGIReaderImpl.java,v 1.1 2005/03/09 23:33:03 srt Exp $ */ public class AGIReaderImpl implements AGIReader { private SocketConnectionFacade socket; private ReplyBuilder replyBuilder; public AGIReaderImpl(SocketConnectionFacade socket) { this.socket = socket; this.replyBuilder = new ReplyBuilderImpl(); } public AGIReply readReply() throws IOException { AGIReply reply; List lines; String line; lines = new ArrayList(); line = socket.readLine(); lines.add(line); // read synopsis and usage if statuscode is 520 if (line.startsWith(Integer .toString(AGIReply.SC_INVALID_COMMAND_SYNTAX))) { while ((line = socket.readLine()) != null) { lines.add(line); if (line.startsWith(Integer .toString(AGIReply.SC_INVALID_COMMAND_SYNTAX))) { break; } } } reply = replyBuilder.buildReply(lines); return reply; } } |