📄 serverinputstream.java
字号:
/* ---------------------------------------------------------------------- The SINUS Firewall -- a TCP/IP packet filter for Linux Written within the SINUS project at the University of Zurich, SWITCH, Telekurs Payserv AG, ETH Zurich. originally based on the sf Firewall Software (C) 1996 by Robert Muchsel and Roland Schmid. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. SINUS Firewall resources: SINUS Homepage: http://www.ifi.unizh.ch/ikm/SINUS/ Firewall Homepage: http://www.ifi.unizh.ch/ikm/SINUS/firewall.html Frequently asked questions: http://www.ifi.unizh.ch/ikm/SINUS/sf_faq.html Mailing list for comments, questions, bug reports: firewall@ifi.unizh.ch ---------------------------------------------------------------------- */package sfclasses;import java.io.*;import sfclasses.*;/** * This class implements an input stream to read data from a firewall system * It uses the I/O functions implemented in the Communicator * class. Filter streams can be used on top of this stream to enhance * functionality. * @version 1.0 11 Dec 1996 * @author Roland E. Schmid */public class ServerInputStream extends InputStream { /** * Initialize the stream and request the file from the firewall. * @param h IP address of the firewall * @param filename Name of the file to read including the full path name. * The file must be in the configuration directory <tt>/etc/firewall.d</tt> * or in the log directory <tt>/var/log</tt>. */ public ServerInputStream(byte[] h, String filename) { host = h; conn = Communicator.openServer(h); if (conn == null) { EOF = true; return; } EOF = !Communicator.requestFile(host, filename); } /** * Read one byte from the input stream * @return read byte or -1 on error */ public int read() throws IOException { if (EOF) return -1; if (bufptr < buffer.length) { bufptr++; return buffer[bufptr-1]; } try { conn.readHeader(); if (conn.readLength == 0) { EOF = true; return -1; } buffer = new byte[conn.readLength]; conn.in.readFully(buffer, 0, conn.readLength); bufptr = 1; return buffer[0]; } catch (Exception e) { throw new IOException(); } } /** * Close the input stream. */ public void close() throws IOException { while (!EOF) { try { conn.readHeader(); } catch (Exception e) { throw new IOException(); } if (conn.readLength == 0) EOF = true; else { buffer = new byte[conn.readLength]; conn.in.readFully(buffer, 0, conn.readLength); } } } /** * Return number of bytes available for reading. If the buffer is * empty but the end of the file is not reached, 1 is returned. */ public int available() { if (EOF) return 0; if (buffer.length > bufptr) return buffer.length - bufptr; return 1; } /** * Check if the end of the file has been reached. * @return true if EOF, false otherwise */ public boolean isEOF() { return EOF; } private Connection conn; private byte[] host; private boolean EOF = true; private byte[] buffer = new byte[0]; private int bufptr = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -