KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > imagero > uio > RandomAccessFactory


1 /*
2  * Copyright (c) Andrey Kuznetsov. All Rights Reserved.
3  *
4  * http://uio.imagero.com
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * o Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * o Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * o Neither the name of imagero Andrei Kouznetsov nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32 package com.imagero.uio;
33
34 import com.imagero.uio.buffer.Buffer;
35 import com.imagero.uio.buffer.BufferManager;
36 import com.imagero.uio.buffer.DefaultBufferManager;
37 import com.imagero.uio.buffer.HTTPBufferManager;
38 import com.imagero.uio.buffer.InputStreamBufferManager;
39 import com.imagero.uio.buffer.MutableBufferManager;
40 import com.imagero.uio.buffer.MutableRABufferManager;
41 import com.imagero.uio.buffer.MutableRAFBufferManager;
42 import com.imagero.uio.buffer.RABufferManager;
43 import com.imagero.uio.buffer.RAFBufferManager;
44 import com.imagero.uio.buffer.OutputStreamBufferManager;
45 import com.imagero.uio.buffer.arrays.CharArrayBufferManager;
46 import com.imagero.uio.buffer.arrays.DoubleArrayBufferManager;
47 import com.imagero.uio.buffer.arrays.FloatArrayBufferManager;
48 import com.imagero.uio.buffer.arrays.IntArrayBufferManager;
49 import com.imagero.uio.buffer.arrays.LongArrayBufferManager;
50 import com.imagero.uio.buffer.arrays.ShortArrayBufferManager;
51
52 import java.io.File JavaDoc;
53 import java.io.IOException JavaDoc;
54 import java.io.InputStream JavaDoc;
55 import java.io.RandomAccessFile JavaDoc;
56 import java.io.OutputStream JavaDoc;
57 import java.net.URL JavaDoc;
58
59 /**
60  * Create RandomAccess/RandomAccess from various resources.<br>
61  * Since all classes in uio and buffer packages was made public,
62  * RandomAccesFactory is no more indispensable and gives not all possibilities.
63  * However ist is very useful as example.
64  *
65  * @author Andrei Kouznetsov
66  * @see RandomAccess
67  * Date: 12.11.2003
68  * Time: 19:32:15
69  */

70 public class RandomAccessFactory {
71     public static final int BIG_ENDIAN = 0x4D4D;
72     public static final int LITTLE_ENDIAN = 0x4949;
73     public static final int AUTO_ENDIAN = 0x0;
74
75     /**
76      * create RandomAccess from BufferManager
77      *
78      * @param sm BufferManager
79      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
80      *
81      * @return RandomAccess
82      *
83      * @throws IOException
84      * @see com.imagero.uio.RandomAccess
85      * @see com.imagero.uio.buffer.BufferManager
86      * @see com.imagero.uio.buffer.DefaultBufferManager
87      * @see com.imagero.uio.buffer.InputStreamBufferManager
88      * @see com.imagero.uio.buffer.Buffer
89      */

90     public static RandomAccess createBuffered(MutableBufferManager sm, int byteOrder) throws IOException JavaDoc {
91         return new RandomAccessBuffer(sm, byteOrder);
92     }
93
94     /**
95      * create RandomAccess from MutableBufferManager with network byte order (BIG_ENDIAN)
96      *
97      * @param sm MutableBufferManager
98      *
99      * @return RandomAccess
100      *
101      * @throws IOException
102      * @see com.imagero.uio.RandomAccess
103      * @see com.imagero.uio.buffer.BufferManager
104      * @see com.imagero.uio.buffer.DefaultBufferManager
105      * @see com.imagero.uio.buffer.InputStreamBufferManager
106      * @see com.imagero.uio.buffer.Buffer
107      */

108     public static RandomAccess createBuffered(MutableBufferManager sm) throws IOException JavaDoc {
109         return new RandomAccessBuffer(sm, BIG_ENDIAN);
110     }
111
112     /**
113      * create RandomAccessRO from BufferManager
114      *
115      * @param sm BufferManager
116      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
117      *
118      * @return RandomAccessRO
119      *
120      * @throws IOException
121      * @see com.imagero.uio.RandomAccessRO
122      * @see com.imagero.uio.buffer.BufferManager
123      * @see com.imagero.uio.buffer.DefaultBufferManager
124      * @see com.imagero.uio.buffer.InputStreamBufferManager
125      * @see com.imagero.uio.buffer.Buffer
126      */

127     public static RandomAccessRO createBufferedRO(BufferManager sm, int byteOrder) throws IOException JavaDoc {
128         return new RandomAccessBufferRO(sm, byteOrder);
129     }
130
131     /**
132      * create RandomAccessRO from BufferManager
133      *
134      * @param sm BufferManager
135      *
136      * @return RandomAccessRO
137      *
138      * @throws IOException
139      * @see com.imagero.uio.RandomAccessRO
140      * @see com.imagero.uio.buffer.BufferManager
141      * @see com.imagero.uio.buffer.DefaultBufferManager
142      * @see com.imagero.uio.buffer.InputStreamBufferManager
143      * @see com.imagero.uio.buffer.Buffer
144      */

145     public static RandomAccessRO createBufferedRO(BufferManager sm) throws IOException JavaDoc {
146         int byteOrder = BIG_ENDIAN;
147         if (sm instanceof RABufferManager) {
148             RABufferManager ram = (RABufferManager) sm;
149             byteOrder = ram.getByteOrder();
150         }
151         return new RandomAccessBufferRO(sm, byteOrder);
152     }
153
154     /**
155      * create RandomAccess from Buffer array.
156      * Same as <code>create(new DefaultBufferManager(buffer));</code>
157      *
158      * @param ds array of Buffers
159      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
160      *
161      * @return RandomAccess
162      *
163      * @throws IOException
164      * @see com.imagero.uio.RandomAccess
165      * @see com.imagero.uio.buffer.BufferManager
166      * @see com.imagero.uio.buffer.DefaultBufferManager
167      * @see com.imagero.uio.buffer.InputStreamBufferManager
168      * @see com.imagero.uio.buffer.Buffer
169      */

170     public static RandomAccess createBuffered(Buffer[] ds, int byteOrder) throws IOException JavaDoc {
171         return createBuffered(new DefaultBufferManager(ds), byteOrder);
172     }
173
174     /**
175      * create RandomAccess from Buffer array with default java byte order (BIG_ENDIAN)
176      * Same as <code>create(new DefaultBufferManager(buffer));</code>
177      *
178      * @param ds Buffer array
179      *
180      * @return RandomAccess
181      *
182      * @throws IOException
183      * @see com.imagero.uio.RandomAccess
184      * @see com.imagero.uio.buffer.BufferManager
185      * @see com.imagero.uio.buffer.DefaultBufferManager
186      * @see com.imagero.uio.buffer.InputStreamBufferManager
187      * @see com.imagero.uio.buffer.Buffer
188      */

189     public static RandomAccess createBuffered(Buffer[] ds) throws IOException JavaDoc {
190         return createBuffered(new DefaultBufferManager(ds), BIG_ENDIAN);
191     }
192
193     /**
194      * create RandomAccessRO from Buffer array.
195      * Same as <code>createRO(new DefaultBufferManager(buffer));</code>
196      *
197      * @param ds Buffer array
198      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
199      *
200      * @return RandomAccessRO
201      *
202      * @throws IOException
203      * @see com.imagero.uio.RandomAccessRO
204      * @see com.imagero.uio.buffer.BufferManager
205      * @see com.imagero.uio.buffer.DefaultBufferManager
206      * @see com.imagero.uio.buffer.InputStreamBufferManager
207      * @see com.imagero.uio.buffer.Buffer
208      */

209     public static RandomAccessRO createBufferedRO(Buffer[] ds, int byteOrder) throws IOException JavaDoc {
210         return createBufferedRO(new DefaultBufferManager(ds), byteOrder);
211     }
212
213     /**
214      * create RandomAccessRO from Buffer array with #BIG_ENDIAN byte order.
215      * Same as <code>createRO(new DefaultBufferManager(buffer));</code>
216      *
217      * @param ds Buffer array
218      *
219      * @return RandomAccessRO
220      *
221      * @throws IOException
222      * @see com.imagero.uio.RandomAccessRO
223      * @see com.imagero.uio.buffer.BufferManager
224      * @see com.imagero.uio.buffer.DefaultBufferManager
225      * @see com.imagero.uio.buffer.InputStreamBufferManager
226      * @see com.imagero.uio.buffer.Buffer
227      */

228     public static RandomAccessRO createBufferedRO(Buffer[] ds) throws IOException JavaDoc {
229         return createBufferedRO(new DefaultBufferManager(ds), BIG_ENDIAN);
230     }
231
232     /**
233      * create RandomAccessRO from InputStream.
234      *
235      * @param in InputStream
236      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
237      *
238      * @return RandomAccessRO
239      *
240      * @throws IOException
241      * @see com.imagero.uio.RandomAccessRO
242      * @see com.imagero.uio.buffer.BufferManager
243      * @see com.imagero.uio.buffer.DefaultBufferManager
244      * @see com.imagero.uio.buffer.InputStreamBufferManager
245      * @see com.imagero.uio.buffer.Buffer
246      */

247     public static RandomAccessRO createBufferedRO(InputStream JavaDoc in, int byteOrder) throws IOException JavaDoc {
248         return new RandomAccessBufferRO(new InputStreamBufferManager(in), byteOrder);
249     }
250
251     /**
252      * create RandomAccessRO from InputStream with default for java byte order (BIG_ENDIAN).
253      *
254      * @param in InputStream
255      *
256      * @return RandomAccessRO
257      *
258      * @throws IOException
259      * @see com.imagero.uio.RandomAccessRO
260      * @see com.imagero.uio.buffer.BufferManager
261      * @see com.imagero.uio.buffer.DefaultBufferManager
262      * @see com.imagero.uio.buffer.InputStreamBufferManager
263      * @see com.imagero.uio.buffer.Buffer
264      */

265     public static RandomAccessRO createBufferedRO(InputStream JavaDoc in) throws IOException JavaDoc {
266         return createBufferedRO(in, BIG_ENDIAN);
267     }
268
269
270     /**
271      * create RandomAccess to read from and write to specified file.
272      *
273      * @param f File to read/write
274      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
275      *
276      * @return RandomAccess
277      *
278      * @throws IOException
279      * @see com.imagero.uio.RandomAccess
280      */

281     public static RandomAccess create(File JavaDoc f, int byteOrder) throws IOException JavaDoc {
282         return create(new RandomAccessFile JavaDoc(f, "rw"), byteOrder);
283     }
284
285     /**
286      * create RandomAccess (with BIG_ENDIAN byte order) to read from and write to specified file.
287      *
288      * @param f File to read/write
289      *
290      * @return RandomAccess
291      *
292      * @throws IOException
293      * @see com.imagero.uio.RandomAccess
294      */

295     public static RandomAccess create(File JavaDoc f) throws IOException JavaDoc {
296         return create(new RandomAccessFile JavaDoc(f, "rw"), BIG_ENDIAN);
297     }
298
299     /**
300      * create RandomAccessRO to read from to specified file.
301      *
302      * @param f File to read
303      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
304      *
305      * @return RandomAccess
306      *
307      * @throws IOException
308      * @see com.imagero.uio.RandomAccessRO
309      */

310     public static RandomAccessRO createRO(File JavaDoc f, int byteOrder) throws IOException JavaDoc {
311         return createRO(new RandomAccessFile JavaDoc(f, "r"), byteOrder);
312     }
313
314     /**
315      * create RandomAccessRO with BIG-ENDIAN byte order to read from to specified file.
316      *
317      * @param f File to read
318      *
319      * @return RandomAccess
320      *
321      * @throws IOException
322      * @see com.imagero.uio.RandomAccessRO
323      */

324     public static RandomAccessRO createRO(File JavaDoc f) throws IOException JavaDoc {
325         return createRO(new RandomAccessFile JavaDoc(f, "r"), BIG_ENDIAN);
326     }
327
328     /**
329      * create RandomAccess to read from and write to file with specified name.
330      *
331      * @param name file name
332      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
333      *
334      * @return RandomAccess
335      *
336      * @throws IOException
337      */

338     public static RandomAccess create(String JavaDoc name, int byteOrder) throws IOException JavaDoc {
339         return create(new RandomAccessFile JavaDoc(name, "rw"), byteOrder);
340     }
341
342     /**
343      * create RandomAccess with BIG-ENDIAN byte order to read from and write to file with specified name.
344      *
345      * @param name file name
346      *
347      * @return RandomAccess
348      *
349      * @throws IOException
350      */

351     public static RandomAccess create(String JavaDoc name) throws IOException JavaDoc {
352         return create(new RandomAccessFile JavaDoc(name, "rw"), BIG_ENDIAN);
353     }
354
355     /**
356      * create RandomAccessRO to read data from file with specified name.
357      *
358      * @param name file name
359      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
360      *
361      * @return RandomAccessRO
362      *
363      * @throws IOException
364      */

365     public static RandomAccessRO createRO(String JavaDoc name, int byteOrder) throws IOException JavaDoc {
366         return createRO(new RandomAccessFile JavaDoc(name, "r"), byteOrder);
367     }
368
369     /**
370      * create RandomAccessRO with BIG-ENDIAN byte order to read data from file with specified name.
371      *
372      * @param name file name
373      *
374      * @return RandomAccessRO
375      *
376      * @throws IOException
377      */

378     public static RandomAccessRO createRO(String JavaDoc name) throws IOException JavaDoc {
379         return createRO(new RandomAccessFile JavaDoc(name, "r"), BIG_ENDIAN);
380     }
381
382     /**
383      * create RandomAccess to read from and write to specified file starting from specified offset in file.
384      *
385      * @param file File to read/write
386      * @param offset start offset in file
387      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
388      *
389      * @return RandomAccess
390      *
391      * @throws IOException
392      */

393     public static RandomAccess create(File JavaDoc file, long offset, int byteOrder) throws IOException JavaDoc {
394         return create(new OffsetRandomAccessFile(file, "rw", offset), byteOrder);
395     }
396
397     /**
398      * create RandomAccess with BIG-ENDIAN byte order to read from and write to specified file starting from specified offset in file.
399      *
400      * @param file File to read/write
401      * @param offset start offset in file
402      *
403      * @return RandomAccess
404      *
405      * @throws IOException
406      */

407     public static RandomAccess create(File JavaDoc file, long offset) throws IOException JavaDoc {
408         return create(new OffsetRandomAccessFile(file, "rw", offset), BIG_ENDIAN);
409     }
410
411     /**
412      * create RandomAccessRO to read from specified file starting from specified offset in file.
413      * this is the OLD unbuffered method to read file (slow for DataInput methods)
414      *
415      * @param file File to read
416      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
417      * @param offset start offset in file
418      *
419      * @return RandomAccessRO
420      *
421      * @throws IOException
422      */

423     public static RandomAccessRO createRO(File JavaDoc file, long offset, int byteOrder) throws IOException JavaDoc {
424         return createRO(new OffsetRandomAccessFile(file, "r", offset), byteOrder);
425     }
426
427     /**
428      * create RandomAccessRO with BIG-ENDIAN byte order to read from specified file starting from specified offset in file.
429      *
430      * @param file File to read
431      * @param offset start offset in file
432      *
433      * @return RandomAccessRO
434      *
435      * @throws IOException
436      */

437     public static RandomAccessRO createRO(File JavaDoc file, long offset) throws IOException JavaDoc {
438         return createRO(new OffsetRandomAccessFile(file, "r", offset), BIG_ENDIAN);
439     }
440
441     /**
442      * create RandomAccess to read from/write to specified segment of the file.
443      *
444      * @param file file to read/write
445      * @param offset start of segment
446      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
447      * @param length segment length
448      *
449      * @return RandomAccess
450      *
451      * @throws IOException
452      */

453     public static RandomAccess create(File JavaDoc file, long offset, long length, int byteOrder) throws IOException JavaDoc {
454         return create(new OffsetRandomAccessFile(file, "rw", offset, length), byteOrder);
455     }
456
457     /**
458      * create bufferer RandomAccess to read from/write to specified segment of the file.
459      *
460      * @param file file to read/write
461      * @param offset start of segment
462      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
463      * @param length segment length
464      *
465      * @return RandomAccess
466      *
467      * @throws IOException
468      */

469     public static RandomAccess createBuffered(File JavaDoc file, long offset, long length, int byteOrder) throws IOException JavaDoc {
470         MutableBufferManager mbm = new MutableRAFBufferManager(new RandomAccessFile JavaDoc(file, "rw"), offset, (int) length);
471         return createBuffered(mbm, byteOrder);
472     }
473
474     /**
475      * create RandomAccess with BIG-ENDIAN byte order to read from/write to specified segment of the file.
476      *
477      * @param file file to read/write
478      * @param offset start of segment
479      * @param length segment length
480      *
481      * @return RandomAccess
482      *
483      * @throws IOException
484      */

485     public static RandomAccess create(File JavaDoc file, long offset, long length) throws IOException JavaDoc {
486         return create(new OffsetRandomAccessFile(file, "rw", offset, length), BIG_ENDIAN);
487     }
488
489     /**
490      * create buffered RandomAccess with BIG-ENDIAN byte order to read from/write to specified segment of the file.
491      *
492      * @param file file to read/write
493      * @param offset start of segment
494      * @param length segment length
495      *
496      * @return RandomAccess
497      *
498      * @throws IOException
499      */

500     public static RandomAccess createBuffered(File JavaDoc file, long offset, long length) throws IOException JavaDoc {
501         return createBuffered(file, offset,length, BIG_ENDIAN);
502     }
503
504     /**
505      * create RandomAccessRO to read from specified segment of the file.
506      *
507      * @param file file to read
508      * @param offset start of segment
509      * @param length segment length
510      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
511      *
512      * @return RandomAccessRO
513      *
514      * @throws IOException
515      */

516     public static RandomAccessRO createRO(File JavaDoc file, long offset, long length, int byteOrder) throws IOException JavaDoc {
517         return createRO(new OffsetRandomAccessFile(file, "r", offset, length), byteOrder);
518     }
519
520     /**
521      * create buffered RandomAccessRO to read from specified segment of the file.
522      *
523      * @param file file to read
524      * @param offset start of segment
525      * @param length segment length
526      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
527      *
528      * @return RandomAccessRO
529      *
530      * @throws IOException
531      */

532     public static RandomAccessRO createBufferedRO(File JavaDoc file, long offset, long length, int byteOrder) throws IOException JavaDoc {
533         BufferManager mbm = new RAFBufferManager(new RandomAccessFile JavaDoc(file, "r"), offset, (int) length);
534         return createBufferedRO(mbm, byteOrder);
535     }
536
537     /**
538      * create RandomAccessRO with BIG-ENDIAN byte order to read from specified segment of the file.
539      *
540      * @param file file to read
541      * @param offset start of segment
542      * @param length segment length
543      *
544      * @return RandomAccessRO
545      *
546      * @throws IOException
547      */

548     public static RandomAccessRO createRO(File JavaDoc file, long offset, long length) throws IOException JavaDoc {
549         return createRO(new OffsetRandomAccessFile(file, "r", offset, length), BIG_ENDIAN);
550     }
551
552     /**
553      * create buffered RandomAccessRO with BIG-ENDIAN byte order to read from specified segment of the file.
554      *
555      * @param file file to read
556      * @param offset start of segment
557      * @param length segment length
558      *
559      * @return RandomAccessRO
560      *
561      * @throws IOException
562      */

563     public static RandomAccessRO createBufferedRO(File JavaDoc file, long offset, long length) throws IOException JavaDoc {
564         BufferManager mbm = new RAFBufferManager(new RandomAccessFile JavaDoc(file, "r"), offset, (int) length);
565         return createBufferedRO(mbm, BIG_ENDIAN);
566     }
567
568     /**
569      * create RandomAccess to read from/write to segment of the file with specified name.
570      *
571      * @param name file name
572      * @param offset start of segment
573      * @param length segment length
574      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
575      *
576      * @return RandomAccess
577      *
578      * @throws IOException
579      */

580     public static RandomAccess create(String JavaDoc name, long offset, long length, int byteOrder) throws IOException JavaDoc {
581         return create(new OffsetRandomAccessFile(name, "rw", offset, length), byteOrder);
582     }
583
584     /**
585      * create buffered RandomAccess to read from/write to segment of the file with specified name.
586      *
587      * @param name file name
588      * @param offset start of segment
589      * @param length segment length
590      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
591      *
592      * @return RandomAccess
593      *
594      * @throws IOException
595      */

596     public static RandomAccess createBuffered(String JavaDoc name, long offset, long length, int byteOrder) throws IOException JavaDoc {
597         MutableBufferManager mbm = new MutableRAFBufferManager(new RandomAccessFile JavaDoc(name, "rw"), offset, (int) length);
598         return createBuffered(mbm, byteOrder);
599     }
600
601     /**
602      * create RandomAccess with BIG-ENDIAN byte order to read from/write to segment of the file with specified name.
603      *
604      * @param name file name
605      * @param offset start of segment
606      * @param length segment length
607      *
608      * @return RandomAccess
609      *
610      * @throws IOException
611      */

612     public static RandomAccess create(String JavaDoc name, long offset, long length) throws IOException JavaDoc {
613         return create(new OffsetRandomAccessFile(name, "rw", offset, length), BIG_ENDIAN);
614     }
615
616     /**
617      * create buffered RandomAccess with BIG-ENDIAN byte order to read from/write to segment of the file with specified name.
618      *
619      * @param name file name
620      * @param offset start of segment
621      * @param length segment length
622      *
623      * @return RandomAccess
624      *
625      * @throws IOException
626      */

627     public static RandomAccess createBuffered(String JavaDoc name, long offset, long length) throws IOException JavaDoc {
628         MutableBufferManager mbm = new MutableRAFBufferManager(new RandomAccessFile JavaDoc(name, "rw"), offset, (int) length);
629         return createBuffered(mbm, BIG_ENDIAN);
630     }
631
632     /**
633      * create RandomAccessRO to read from segment of the file with specified name.
634      *
635      * @param name file name
636      * @param offset start of segment
637      * @param length segment length
638      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
639      *
640      * @return RandomAccessRO
641      *
642      * @throws IOException
643      */

644     public static RandomAccessRO createRO(String JavaDoc name, long offset, long length, int byteOrder) throws IOException JavaDoc {
645         return createRO(new OffsetRandomAccessFile(name, "r", offset, length), byteOrder);
646     }
647
648     /**
649      * create buffered RandomAccessRO to read from segment of the file with specified name.
650      *
651      * @param name file name
652      * @param offset start of segment
653      * @param length segment length
654      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
655      *
656      * @return RandomAccessRO
657      *
658      * @throws IOException
659      */

660     public static RandomAccessRO createBufferedRO(String JavaDoc name, long offset, long length, int byteOrder) throws IOException JavaDoc {
661         BufferManager mbm = new RAFBufferManager(new RandomAccessFile JavaDoc(name, "r"), offset, (int) length);
662         return createBufferedRO(mbm, byteOrder);
663     }
664
665     /**
666      * create RandomAccessRO with BIG-ENDIAN byte order to read from segment of the file with specified name.
667      *
668      * @param name file name
669      * @param offset start of segment
670      * @param length segment length
671      *
672      * @return RandomAccessRO
673      *
674      * @throws IOException
675      */

676     public static RandomAccessRO createRO(String JavaDoc name, long offset, long length) throws IOException JavaDoc {
677         return createRO(new OffsetRandomAccessFile(name, "r", offset, length), BIG_ENDIAN);
678     }
679
680     /**
681      * create RandomAccessRO with BIG-ENDIAN byte order to read from segment of the file with specified name.
682      *
683      * @param name file name
684      * @param offset start of segment
685      * @param length segment length
686      *
687      * @return RandomAccessRO
688      *
689      * @throws IOException
690      */

691     public static RandomAccessRO createBufferedRO(String JavaDoc name, long offset, long length) throws IOException JavaDoc {
692         BufferManager mbm = new RAFBufferManager(new RandomAccessFile JavaDoc(name, "r"), offset, (int) length);
693         return createBufferedRO(mbm, BIG_ENDIAN);
694     }
695
696     /**
697      * create RandomAccess from specified RandomAccessFile
698      *
699      * @param raf RandomAccessFile
700      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
701      *
702      * @return RandomAccess
703      */

704     public static RandomAccess create(RandomAccessFile JavaDoc raf, int byteOrder) throws IOException JavaDoc {
705         return new RandomAccessFileWrapper(raf, byteOrder);
706     }
707
708     /**
709      * create buffered RandomAccess from specified RandomAccessFile
710      *
711      * @param raf RandomAccessFile
712      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
713      *
714      * @return RandomAccess
715      */

716     public static RandomAccess createBuffered(RandomAccessFile JavaDoc raf, int byteOrder) throws IOException JavaDoc {
717         MutableBufferManager mbm = new MutableRAFBufferManager(raf, 0, (int) raf.length());
718         return createBuffered(mbm, byteOrder);
719     }
720
721     /**
722      * create RandomAccess with BIG-ENDIAN byte order from specified RandomAccessFile
723      *
724      * @param raf RandomAccessFile
725      *
726      * @return RandomAccess
727      */

728     public static RandomAccess create(RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
729         return new RandomAccessFileWrapper(raf, BIG_ENDIAN);
730     }
731
732     /**
733      * create RandomAccess with BIG-ENDIAN byte order from specified RandomAccessFile
734      *
735      * @param raf RandomAccessFile
736      *
737      * @return RandomAccess
738      */

739     public static RandomAccess createBuffered(RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
740         MutableBufferManager mbm = new MutableRAFBufferManager(raf, 0, (int) raf.length());
741         return createBuffered(mbm, BIG_ENDIAN);
742     }
743
744     /**
745      * create RandomAccess with BIG-ENDIAN byte order from specified RandomAccessFile
746      *
747      * @param out OutputStream
748      *
749      * @return RandomAccess
750      */

751     public static RandomAccess createBuffered(OutputStream JavaDoc out) throws IOException JavaDoc {
752         MutableBufferManager mbm = new OutputStreamBufferManager(out);
753         return createBuffered(mbm, BIG_ENDIAN);
754     }
755
756     /**
757      * create RandomAccessRO from specified RandomAccessFile
758      *
759      * @param raf RandomAccessFile
760      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
761      *
762      * @return RandomAccessRO
763      */

764     public static RandomAccessRO createRO(RandomAccessFile JavaDoc raf, int byteOrder) throws IOException JavaDoc {
765         return new RandomAccessFileWrapperRO(raf, byteOrder);
766     }
767
768     /**
769      * create buffered RandomAccessRO from specified RandomAccessFile
770      *
771      * @param raf RandomAccessFile
772      * @return RandomAccessRO
773      */

774     public static RandomAccessRO createBufferedRO(RandomAccessFile JavaDoc raf, int byteOrder) throws IOException JavaDoc {
775         BufferManager mbm = new RAFBufferManager(raf, 0, (int) raf.length());
776         return createBufferedRO(mbm, byteOrder);
777     }
778
779     /**
780      * create RandomAccessRO with BIG-ENDIAN byte order from specified RandomAccessFile
781      *
782      * @param raf RandomAccessFile
783      *
784      * @return RandomAccessRO
785      */

786     public static RandomAccessRO createRO(RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
787         return new RandomAccessFileWrapperRO(raf, BIG_ENDIAN);
788     }
789
790     /**
791      * create buffered RandomAccessRO with BIG-ENDIAN byte order from specified RandomAccessFile
792      *
793      * @param raf RandomAccessFile
794      *
795      * @return RandomAccessRO
796      */

797     public static RandomAccessRO createBufferedRO(RandomAccessFile JavaDoc raf) throws IOException JavaDoc {
798         BufferManager mbm = new RAFBufferManager(raf, 0, (int) raf.length());
799         return createBufferedRO(mbm, BIG_ENDIAN);
800     }
801
802     /**
803      * create RandomAccess from specified byte array
804      *
805      * @param data byte array
806      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
807      *
808      * @return RandomAccess
809      *
810      * @throws IOException
811      */

812     public static RandomAccess create(byte[] data, int byteOrder) throws IOException JavaDoc {
813         return new RandomAccessByteArray(data, byteOrder);
814     }
815
816     /**
817      * create RandomAccess with BIG-ENDIAN byte order from specified byte array
818      *
819      * @param data byte array
820      *
821      * @return RandomAccess
822      *
823      * @throws IOException
824      */

825     public static RandomAccess create(byte[] data) throws IOException JavaDoc {
826         return new RandomAccessByteArray(data, BIG_ENDIAN);
827     }
828
829     /**
830      * create RandomAccessRO from specified byte array
831      *
832      * @param data byte array
833      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
834      *
835      * @return RandomAccessRO
836      *
837      * @throws IOException
838      */

839     public static RandomAccessRO createRO(byte[] data, int byteOrder) throws IOException JavaDoc {
840         return new RandomAccessByteArrayRO(data, byteOrder);
841     }
842
843     /**
844      * create RandomAccessRO with BIG-ENDIAN byte order from specified byte array
845      *
846      * @param data byte array
847      *
848      * @return RandomAccessRO
849      *
850      * @throws IOException
851      */

852     public static RandomAccessRO createRO(byte[] data) throws IOException JavaDoc {
853         return new RandomAccessByteArrayRO(data, BIG_ENDIAN);
854     }
855
856     /**
857      * create RandomAccess from specified segment of byte array
858      *
859      * @param data byte array