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
00018
00019
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
00033
00034
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
00054
00055
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
00076
00077
00078
00079 public void reset () throws IOException {
00080 throw new IOException ("Reset not supported.");
00081 }
00082
00083
00084
00085
00086
00087
00088 public void mark (int readAheadLimit) throws IOException {
00089 throw new IOException ("Mark not supported");
00090 }
00091
00092
00093
00094
00095
00096
00097 public boolean markSupported () {
00098 return false;
00099 }
00100 }