JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / src / com / stevesoft / pat / wrap / RandomAccessFileWrap.java
1 //
2 // This software is now distributed according to
3 // the Lesser Gnu Public License.  Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
5 // the details.
6 //    -- Happy Computing!
7 //
8 package com.stevesoft.pat.wrap;
9
10
11 /**
12  * Provides a wrapper for a RandomAccessFile so that it can be searched by
13  * Regex.
14  */
15 public class RandomAccessFileWrap //implements StringLike
16 {
17 //
18 //  long offset = 0;
19 //
20 //  public void setOffset(long o)
21 //  {
22 //    offset = o;
23 //    i0 = iend = 0;
24 //  }
25 //
26 //  public long getOffset()
27 //  {
28 //    return offset;
29 //  }
30 //
31 //  RandomAccessFile raf;
32 //
33 //  int i0 = 0, iend = 0;
34 //
35 //  byte[] buf = new byte[1024];
36 //
37 //  public int getBufferSize()
38 //  {
39 //    return buf.length;
40 //  }
41 //
42 //  public void setBufferSize(int bs)
43 //  {
44 //    buf = new byte[bs];
45 //    i0 = iend = 0;
46 //  }
47 //
48 //  public RandomAccessFileWrap(String file) throws IOException
49 //  {
50 //    this.raf = new RandomAccessFile(file, "r");
51 //  }
52 //
53 //  public RandomAccessFileWrap(RandomAccessFile raf)
54 //  {
55 //    this.raf = raf;
56 //  }
57 //
58 //  public char charAt(int i)
59 //  {
60 //    if (i >= i0 && i < iend)
61 //    {
62 //      return (char) buf[i - i0];
63 //    }
64 //
65 //    try
66 //    {
67 //      i0 = i - 5;
68 //      // if(i0+offset<0) i0=(int)(-offset);
69 //      if (i0 < 0)
70 //      {
71 //        i0 = 0;
72 //      }
73 //      raf.seek(i0 + offset);
74 //      iend = i0 + raf.read(buf, 0, buf.length);
75 //
76 //      if (i >= i0 && i < iend)
77 //      {
78 //        return (char) buf[i - i0];
79 //      }
80 //    } catch (Throwable t)
81 //    {
82 //    }
83 //
84 //    throw new ArrayIndexOutOfBoundsException(MessageManager.formatMessage("exception.out_of_bounds_for_file", new String[]{
85 //              Integer.valueOf(i).toString(),
86 //              Integer.valueOf(i0).toString(),
87 //              Integer.valueOf(iend).toString()
88 //    }));
89 //  }
90 //
91 //  public String toString()
92 //  {
93 //    throw new Error(MessageManager.getString("error.not_implemented"));
94 //  }
95 //
96 //  public int length()
97 //  {
98 //    try
99 //    {
100 //      long len = raf.length() - offset;
101 //      if (len > Integer.MAX_VALUE)
102 //      {
103 //        return Integer.MAX_VALUE;
104 //      }
105 //      return (int) len;
106 //    } catch (IOException ioe)
107 //    {
108 //      return 0;
109 //    }
110 //  }
111 //
112 //  public String substring(int i1, int i2)
113 //  {
114 //    StringBuffer sb = new StringBuffer();
115 //    for (int i = i1; i < i2; i++)
116 //    {
117 //      sb.append(charAt(i));
118 //    }
119 //    return sb.toString();
120 //  }
121 //
122 //  public Object unwrap()
123 //  {
124 //    return raf;
125 //  }
126 //
127 //  public static void main(String[] files) throws IOException
128 //  {
129 //    for (int i = 0; i < files.length; i++)
130 //    {
131 //      RandomAccessFileWrap fw = new RandomAccessFileWrap(
132 //              new RandomAccessFile(files[i], "r"));
133 //      Regex r = new Regex("toString\\(\\) *(?@{})");
134 //      r.setGFlag(true);
135 //      r.optimize();
136 //      System.out.print(files[i] + " ");
137 //      int j = 0;
138 //      do
139 //      {
140 //        if (r.searchFromLike(fw, j))
141 //        {
142 //          System.out.println("Matched at index: " + r.matchedFrom());
143 //          j = r.matchedTo();
144 //        }
145 //        else
146 //        {
147 //          System.out.println("not found");
148 //        }
149 //        System.out.println(r.stringMatched());
150 //      } while (r.didMatch());
151 //    }
152 //  }
153 //
154 //  public BasicStringBufferLike newStringBufferLike()
155 //  {
156 //    return new StringBufferWrap();
157 //  }
158 //
159 //  public int indexOf(char c)
160 //  {
161 //    for (int i = 0; i < length(); i++)
162 //    {
163 //      if (charAt(i) == c)
164 //      {
165 //        return i;
166 //      }
167 //    }
168 //    return -1;
169 //  }
170 }