src/org/gel/mauve/format/RawFastaBridgeFilterReader.java

Go to the documentation of this file.
00001 package org.gel.mauve.format;
00002 
00003 import java.io.FilterReader;
00004 import java.io.IOException;
00005 import java.io.Reader;
00006 
00007 public class RawFastaBridgeFilterReader extends FilterReader {
00008         private final static String HEADER = ">raw\n";
00009 
00010         private int remainingHeader = HEADER.length ();
00011 
00012         protected RawFastaBridgeFilterReader (Reader in) {
00013                 super (in);
00014         }
00015 
00016         /*
00017          * (non-Javadoc)
00018          * 
00019          * @see java.io.Reader#read()
00020          */
00021         public int read () throws IOException {
00022                 if (remainingHeader > 0) {
00023                         char c = HEADER.charAt (HEADER.length () - remainingHeader);
00024                         remainingHeader--;
00025                         return c;
00026                 } else {
00027                         return super.read ();
00028                 }
00029         }
00030 
00031         /*
00032          * (non-Javadoc)
00033          * 
00034          * @see java.io.Reader#read(char[], int, int)
00035          */
00036         public int read (char [] cbuf, int off, int len) throws IOException {
00037                 if (remainingHeader > 0) {
00038                         int counter = 0;
00039 
00040                         while (remainingHeader > 0) {
00041                                 cbuf[off] = (char) read ();
00042                                 off++;
00043                                 len--;
00044                                 counter++;
00045                         }
00046                         return counter + super.read (cbuf, off, len);
00047                 } else {
00048                         return super.read (cbuf, off, len);
00049                 }
00050         }
00051 
00052         /*
00053          * (non-Javadoc)
00054          * 
00055          * @see java.io.Reader#skip(long)
00056          */
00057         public long skip (long n) throws IOException {
00058                 if (remainingHeader > 0) {
00059                         if (n <= remainingHeader) {
00060                                 remainingHeader = remainingHeader - (int) n;
00061                                 return n;
00062                         } else {
00063                                 int oldRemaining = remainingHeader;
00064                                 remainingHeader = 0;
00065                                 n = n - oldRemaining;
00066                                 return super.skip (n) + oldRemaining;
00067                         }
00068 
00069                 } else {
00070                         return super.skip (n);
00071                 }
00072         }
00073 
00074         /*
00075          * (non-Javadoc)
00076          * 
00077          * @see java.io.Reader#reset()
00078          */
00079         public void reset () throws IOException {
00080                 throw new IOException ("Reset not supported.");
00081         }
00082 
00083         /*
00084          * (non-Javadoc)
00085          * 
00086          * @see java.io.Reader#mark(int)
00087          */
00088         public void mark (int readAheadLimit) throws IOException {
00089                 throw new IOException ("Mark not supported");
00090         }
00091 
00092         /*
00093          * (non-Javadoc)
00094          * 
00095          * @see java.io.Reader#markSupported()
00096          */
00097         public boolean markSupported () {
00098                 return false;
00099         }
00100 }

Generated on Mon Aug 19 06:03:41 2013 for Mauve by doxygen 1.3.6