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
8 package com.stevesoft.pat.wrap;
12 * Provides a wrapper for a RandomAccessFile so that it can be searched by
15 public class RandomAccessFileWrap //implements StringLike
20 // public void setOffset(long o)
26 // public long getOffset()
31 // RandomAccessFile raf;
33 // int i0 = 0, iend = 0;
35 // byte[] buf = new byte[1024];
37 // public int getBufferSize()
42 // public void setBufferSize(int bs)
44 // buf = new byte[bs];
48 // public RandomAccessFileWrap(String file) throws IOException
50 // this.raf = new RandomAccessFile(file, "r");
53 // public RandomAccessFileWrap(RandomAccessFile raf)
58 // public char charAt(int i)
60 // if (i >= i0 && i < iend)
62 // return (char) buf[i - i0];
68 // // if(i0+offset<0) i0=(int)(-offset);
73 // raf.seek(i0 + offset);
74 // iend = i0 + raf.read(buf, 0, buf.length);
76 // if (i >= i0 && i < iend)
78 // return (char) buf[i - i0];
80 // } catch (Throwable t)
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()
91 // public String toString()
93 // throw new Error(MessageManager.getString("error.not_implemented"));
96 // public int length()
100 // long len = raf.length() - offset;
101 // if (len > Integer.MAX_VALUE)
103 // return Integer.MAX_VALUE;
106 // } catch (IOException ioe)
112 // public String substring(int i1, int i2)
114 // StringBuffer sb = new StringBuffer();
115 // for (int i = i1; i < i2; i++)
117 // sb.append(charAt(i));
119 // return sb.toString();
122 // public Object unwrap()
127 // public static void main(String[] files) throws IOException
129 // for (int i = 0; i < files.length; i++)
131 // RandomAccessFileWrap fw = new RandomAccessFileWrap(
132 // new RandomAccessFile(files[i], "r"));
133 // Regex r = new Regex("toString\\(\\) *(?@{})");
136 // System.out.print(files[i] + " ");
140 // if (r.searchFromLike(fw, j))
142 // System.out.println("Matched at index: " + r.matchedFrom());
143 // j = r.matchedTo();
147 // System.out.println("not found");
149 // System.out.println(r.stringMatched());
150 // } while (r.didMatch());
154 // public BasicStringBufferLike newStringBufferLike()
156 // return new StringBufferWrap();
159 // public int indexOf(char c)
161 // for (int i = 0; i < length(); i++)
163 // if (charAt(i) == c)