pop3inputstream.java~1~
来自「实例大全」· JAVA~1~ 代码 · 共 121 行
JAVA~1~
121 行
package injektilo.net;
import java.io.*;
/**
* Utility class used to retrieve messages using the Pop3Connection
* class.
*
* <p>Copyright (c) 1998 Jason Diamond</p>
*
* <p>sendangels@usa.net<br>
* http://www.geocities.com/ResearchTriangle/Thinktank/8343/</p>
*
* @author Jason Diamond
* @version 1.1.1
*
* History:
*
* 4-Nov-1998 v1.1.1
* initial release
*
*/
public class Pop3InputStream
extends FilterInputStream
{
public Pop3InputStream(InputStream is) {
super(is);
}
private static final int CR = 13;
private static final int LF = 10;
private static final int DOT = 46;
private boolean eof;
private boolean gotCR;
private boolean gotLF;
public int read()
throws IOException
{
if (eof) {
return -1;
}
int c = in.read();
if (c == CR) {
gotCR = true;;
return c;
}
if (gotCR & c == LF) {
gotLF = true;
return c;
}
// if (c == LF) {
// gotLF = true;
// return c;
// }
if (gotLF) {
if (c == DOT) {
c = in.read();
if (c == CR) {
c = in.read();
if (c == LF) {
eof = true;
return -1;
}
}
}
gotCR = false;
gotLF = false;
}
return c;
}
/* The default FilterInputStream calls in.read(byte[], int, int)
* which calls whatever read() method in implements.
* Therefore, we have to override that with basically the same
* code but make sure it calls the read() method defined above.
*/
public int read(byte[] buf, int off, int len)
throws IOException
{
if (len <= 0) {
return 0;
}
int c = read();
if (c == -1) {
return -1;
}
buf[off] = (byte) c;
int i = 1;
try {
for (; i < len ; ++i) {
c = read();
if (c == -1) {
break;
}
if (buf != null) {
buf[off + i] = (byte) c;
}
}
} catch (IOException e) {}
return i;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?