打开系统文件最大连接数
2012-08-30 09:37
155 查看
package normal; /* * Copyright (c) 2004 David Flanagan. All rights reserved. * This code is from the book Java Examples in a Nutshell, 3nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose, * including teaching and use in open-source projects. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book, * please visit http://www.davidflanagan.com/javaexamples3. */ import java.io.*; /** * A simple FilterReader that strips HTML tags (or anything between * pairs of angle brackets) out of a stream of characters. **/ public class RemoveHTMLReader extends FilterReader { /** A trivial constructor. Just initialize our superclass */ public RemoveHTMLReader(Reader in) { super(in); } boolean intag = false; // Used to remember whether we are "inside" a tag /** * This is the implementation of the no-op read() method of FilterReader. * It calls in.read() to get a buffer full of characters, then strips * out the HTML tags. (in is a protected field of the superclass). **/ public int read(char[] buf, int from, int len) throws IOException { int numchars = 0; // how many characters have been read // Loop, because we might read a bunch of characters, then strip them // all out, leaving us with zero characters to return. while (numchars == 0) { numchars = in.read(buf, from, len); // Read characters if (numchars == -1) return -1; // Check for EOF and handle it. // Loop through the characters we read, stripping out HTML tags. // Characters not in tags are copied over previous tags int last = from; // Index of last non-HTML char for(int i = from; i < from + numchars; i++) { if (!intag) { // If not in an HTML tag if (buf[i] == '<') intag = true; // check for tag start else buf[last++] = buf[i]; // and copy the character } else if (buf[i] == '>') intag = false; // check for end of tag } numchars = last - from; // Figure out how many characters remain } // And if it is more than zero characters return numchars; // Then return that number. } /** * This is another no-op read() method we have to implement. We * implement it in terms of the method above. Our superclass implements * the remaining read() methods in terms of these two. **/ public int read() throws IOException { char[] buf = new char[1]; int result = read(buf, 0, 1); if (result == -1) return -1; else return (int)buf[0]; } /** This class defines a main() method to test the RemoveHTMLReader */ public static class Test { /** The test program: read a text file, strip HTML, print to console */ public static void main(String[] args) { try { // if (args.length != 1) // throw new IllegalArgumentException("Wrong number of args"); // Create a stream to read from the file and strip tags from it BufferedReader in = new BufferedReader( new RemoveHTMLReader(new FileReader("d:/城院公告.htm"))); // Read line by line, printing lines to the console String line; while((line = in.readLine()) != null) System.out.println(line); in.close(); // Close the stream. } catch(Exception e) { System.err.println(e); System.err.println("Usage: java RemoveHTMLReader$Test" + " <filename>"); } } } }
相关文章推荐
- ubuntu12修改系统最大打开文件数
- 关于系统打开的最大文件数限制
- 服务器异常java.io.IOException: Too many open files(系统最大文件打开数限制)
- Ubuntu 12 ulimit 系统最大打开文件个数设置
- linux系统增加系统的最大打开文件数
- 关于系统打开的最大文件数限制
- Ubuntu 12 ulimit 系统最大打开文件个数 设置
- linux系统初始化--修改系统打开文件的最大数量
- ubuntu linux 修改socket最大连接数,同时也是文件最大打开数
- 解除 Linux 系统的最大进程数和最大文件打开数限制
- Ubuntu linux修改socket最大连接数,同时也是文件最大打开数
- 修改linux系统的最大打开文件数
- Ubuntu系统中最大柄数(最大文件打开数)修改办法
- 修改linux系统最大打开文件数
- centos 修改系统打开最大文件数限制 too many open files的解决方法
- 修改linux系统的最大打开文件数
- linux增加系统最大文件打开数量
- ubuntu系统修改系统最大打开文件数的步骤
- 系统进程打开文件最大句柄数的限制
- 高并发socket/tcp网络最大连接数所受的限制问题,ulimit文件打开数,文件描述符