/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/LscpInputStream.java
ViewVC logotype

Annotation of /jlscp/trunk/src/org/linuxsampler/lscp/LscpInputStream.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1202 - (hide annotations) (download)
Thu May 24 20:17:25 2007 UTC (16 years, 11 months ago) by iliev
File size: 2640 byte(s)
* updated to version 0.5a

1 iliev 596 /*
2     * jlscp - a java LinuxSampler control protocol API
3     *
4 iliev 1139 * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 596 *
6     * This file is part of jlscp.
7     *
8     * jlscp is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * jlscp is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with jlscp; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.linuxsampler.lscp;
24    
25     import java.io.InputStream;
26     import java.io.IOException;
27    
28    
29     /**
30     *
31     * @author Grigor Iliev
32     */
33     class LscpInputStream {
34     private InputStream in;
35     private StringBuffer buf = new StringBuffer();
36    
37     /**
38     * Creates a new instance of LscpInputStream.
39     *
40     */
41     public
42     LscpInputStream(InputStream in) {
43     this.in = in;
44     }
45    
46     /**
47     * Reads a line.
48     * This method is thread safe.
49     *
50     * @return A string containing the next line readed from the stream or <code>null</code>
51     * if the end of the stream has been reached.
52     *
53     * @throws LscpException If the end of line or file is reached unexpectedly.
54     * @throws IOException If an I/O error occurs.
55     */
56     public synchronized String
57     readLine() throws IOException, LscpException {
58     int i;
59     buf.setLength(0);
60    
61     while((i = in.read()) != -1) {
62     if(i == '\r') {
63     checkLF();
64     break;
65     }
66     buf.append((char)i);
67     }
68    
69     if(i == -1) {
70     if(buf.length() > 0)
71     throw new LscpException(LscpI18n.getLogMsg("LscpInputStream.EOL!"));
72     return null;
73     }
74 iliev 1202
75 iliev 596 return buf.toString();
76     }
77    
78     /**
79     * Returns the number of bytes that can be read from this input stream without blocking.
80     *
81     * @return The number of bytes that can be read from this input stream without blocking.
82     * @throws IOException If an I/O error occurs.
83     */
84     public synchronized int
85     available() throws IOException { return in.available(); }
86    
87     private void
88     skipLine() throws IOException, LscpException {
89     int i;
90     while((i = in.read()) != -1) {
91     if(i == '\r') {
92     checkLF();
93     break;
94     }
95     }
96     }
97    
98     private void
99     checkLF() throws IOException, LscpException {
100     int i = in.read();
101     if(i == -1) throw new LscpException(LscpI18n.getLogMsg("LscpInputStream.EOF!"));
102     if(i != '\n') throw new LscpException(LscpI18n.getLogMsg("LscpInputStream.EOL!"));
103     }
104     }

  ViewVC Help
Powered by ViewVC