001 package com.hs.mail.io;
002
003 import java.io.IOException;
004 import java.io.InputStream;
005
006 public class CountingInputStream extends InputStream {
007
008 private InputStream in;
009
010 private int lineCount;
011
012 private int octetCount;
013
014 public CountingInputStream(InputStream in) {
015 super();
016 this.in = in;
017 }
018
019 @Override
020 public int read() throws IOException {
021 int next = in.read();
022 if (next > 0) {
023 octetCount++;
024 if (next == '\r') {
025 lineCount++;
026 }
027 }
028 return next;
029 }
030
031 public int getLineCount() {
032 return lineCount;
033 }
034
035 public int getOctetCount() {
036 return octetCount;
037 }
038
039 public void readAll() throws IOException {
040 while (read() > 0)
041 ;
042 }
043
044 }