PrintableInputStreampublic class PrintableInputStream extends FilterInputStream
Constructors Summary |
---|
public PrintableInputStream(InputStream in)
super(in);
|
Methods Summary |
---|
public static void | main(java.lang.String[] args)
for (int i = 0; i < args.length; i++) {
FileInputStream fin = new FileInputStream(args[i]);
PrintableInputStream pin = new PrintableInputStream(fin);
while (true) {
int c = pin.read();
if (c == -1) break;
System.out.write(c);
}
}
| public int | read()
int b = in.read();
// printing, ASCII characters
if (b >= 32 && b <= 126) return b;
// carriage return, linefeed, tab, and end of file
else if (b == 10 || b == 13 || b == 9 || b == -1) return b;
// non-printing characters
else return '?";
| public int | read(byte[] data, int offset, int length)
int result = in.read(data, offset, length);
for (int i = offset; i < offset+result; i++) {
// do nothing with the printing characters
// carriage return, linefeed, tab, and end of file
if (data[i] == 10 || data[i] == 13 || data[i] == 9 || data[i] == -1) ;
// non-printing characters
else if (data[i] < 32 || data[i] > 126) data[i] = (byte) '?";
}
return result;
|
|