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
860      * @param off start of segment
861      * @param length segment length
862      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
863      *
864      * @return RandomAccess
865      *
866      * @throws IOException
867      */

868     public static RandomAccess create(byte[] data, int off, int length, int byteOrder) throws IOException JavaDoc {
869         return new RandomAccessByteArray(data, off, length, byteOrder);
870     }
871
872     /**
873      * create RandomAccess with BIG-ENDIAN byte order from specified segment of byte array
874      *
875      * @param data byte array
876      * @param off start of segment
877      * @param length segment length
878      *
879      * @return RandomAccess
880      *
881      * @throws IOException
882      */

883     public static RandomAccess create(byte[] data, int off, int length) throws IOException JavaDoc {
884         return new RandomAccessByteArray(data, off, length, BIG_ENDIAN);
885     }
886
887     /**
888      * create RandomAccessRO from specified segment of byte array
889      *
890      * @param data byte array
891      * @param off start of segment
892      * @param length segment length
893      * @param byteOrder if AUTO_ENDIAN then byte order is detected. If detection failed then byteOrder is set to BIG_ENDIAN
894      *
895      * @return RandomAccessRO
896      *
897      * @throws IOException
898      */

899     public static RandomAccessRO createRO(byte[] data, int off, int length, int byteOrder) throws IOException JavaDoc {
900         return new RandomAccessByteArrayRO(data, off, length, byteOrder);
901     }
902
903     /**
904      * create RandomAccessRO with BIG-ENDIAN byte order from specified segment of byte array
905      *
906      * @param data byte array
907      * @param off start of segment
908      * @param length segment length
909      *
910      * @return RandomAccessRO
911      *
912      * @throws IOException
913      */

914     public static RandomAccessRO createRO(byte[] data, int off, int length) throws IOException JavaDoc {
915         return new RandomAccessByteArrayRO(data, off, length, BIG_ENDIAN);
916     }
917
918
919     /**
920      * create RandomAccessRO (buffered) from specified URL.
921      *
922      * @param url URL
923      *
924      * @return RandomAccessRO
925      *
926      * @throws IOException
927      */

928     public static RandomAccessRO createBufferedRO(URL JavaDoc url) throws IOException JavaDoc {
929         return createBufferedRO(new HTTPBufferManager(url));
930     }
931
932     /**
933      * create RandomAccessRO from specified RandomAccessRO.
934      *
935      * @param ro RandomAccessRO
936      * @param offset offset in ro
937      * @param length length of created RandomAccessRO
938      *
939      * @return RandomAccessRO
940      *
941      * @throws IOException
942      */

943     public static RandomAccessRO createBufferedRO(RandomAccessRO ro, long offset, int length) throws IOException JavaDoc {
944         return createBufferedRO(new RABufferManager(ro, offset, length));
945     }
946
947     /**
948      * create RandomAccess from specified RandomAccess.
949      *
950      * @param ro RandomAccess
951      * @param offset offset in ro
952      * @param length length of created RandomAccess
953      *
954      * @return RandomAccessRO
955      *
956      * @throws IOException
957      */

958     public static RandomAccess createBuffered(RandomAccess ro, long offset, int length) throws IOException JavaDoc {
959         return createBuffered(new MutableRABufferManager(ro, offset, length));
960     }
961
962     /**
963      * Create RandomAccessRO from short array
964      *
965      * @param data short array
966      *
967      * @return RandomAccessRO
968      *
969      * @throws IOException
970      */

971     public static RandomAccessRO createBufferedRO(short[] data) throws IOException JavaDoc {
972         return createBufferedRO(new ShortArrayBufferManager(data));
973     }
974
975     /**
976      * Create RandomAccess from short array
977      *
978      * @param data short array
979      *
980      * @return RandomAccess
981      *
982      * @throws IOException
983      */

984     public static RandomAccess createBuffered(short[] data) throws IOException JavaDoc {
985         return createBuffered(new ShortArrayBufferManager(data));
986     }
987
988     /**
989      * Create RandomAccessRO from short array
990      *
991      * @param data short array
992      * @param off start offset
993      * @param length required length
994      *
995      * @return RandomAccess
996      *
997      * @throws IOException
998      */

999     public static RandomAccessRO createBufferedRO(short[] data, int off, int length) throws IOException JavaDoc {
1000        return createBufferedRO(new ShortArrayBufferManager(data, off, length));
1001    }
1002
1003    /**
1004     * Create RandomAccess from short array
1005     *
1006     * @param data short array
1007     * @param off start offset
1008     * @param length required length
1009     *
1010     * @return RandomAccess
1011     *
1012     * @throws IOException
1013     */

1014    public static RandomAccess createBuffered(short[] data, int off, int length) throws IOException JavaDoc {
1015        return createBuffered(new ShortArrayBufferManager(data, off, length));
1016    }
1017
1018    /**
1019     * Create RandomAccessRO from char array
1020     *
1021     * @param data char array
1022     *
1023     * @return RandomAccessRO
1024     *
1025     * @throws IOException
1026     */

1027    public static RandomAccessRO createBufferedRO(char[] data) throws IOException JavaDoc {
1028        return createBufferedRO(new CharArrayBufferManager(data));
1029    }
1030
1031    /**
1032     * Create RandomAccess from char array
1033     *
1034     * @param data char array
1035     *
1036     * @return RandomAccess
1037     *
1038     * @throws IOException
1039     */

1040    public static RandomAccess createBuffered(char[] data) throws IOException JavaDoc {
1041        return createBuffered(new CharArrayBufferManager(data));
1042    }
1043
1044    /**
1045     * Create RandomAccessRO from char array
1046     *
1047     * @param data char array
1048     * @param off start offset
1049     * @param length required length
1050     *
1051     * @return RandomAccess
1052     *
1053     * @throws IOException
1054     */

1055    public static RandomAccessRO createBufferedRO(char[] data, int off, int length) throws IOException JavaDoc {
1056        return createBufferedRO(new CharArrayBufferManager(data, off, length));
1057    }
1058
1059    /**
1060     * Create RandomAccess from char array
1061     *
1062     * @param data char array
1063     * @param off start offset
1064     * @param length required length
1065     *
1066     * @return RandomAccess
1067     *
1068     * @throws IOException
1069     */

1070    public static RandomAccess createBuffered(char[] data, int off, int length) throws IOException JavaDoc {
1071        return createBuffered(new CharArrayBufferManager(data, off, length));
1072    }
1073
1074    /**
1075     * Create RandomAccessRO from int array
1076     *
1077     * @param data int array
1078     *
1079     * @return RandomAccess
1080     *
1081     * @throws IOException
1082     */

1083    public static RandomAccessRO createBufferedRO(int[] data) throws IOException JavaDoc {
1084        return createBufferedRO(new IntArrayBufferManager(data));
1085    }
1086
1087    /**
1088     * Create RandomAccess from int array
1089     *
1090     * @param data int array
1091     *
1092     * @return RandomAccess
1093     *
1094     * @throws IOException
1095     */

1096    public static RandomAccess createBuffered(int[] data) throws IOException JavaDoc {
1097        return createBuffered(new IntArrayBufferManager(data));
1098    }
1099
1100    /**
1101     * Create RandomAccessRO from int array
1102     *
1103     * @param data int array
1104     * @param off start offset
1105     * @param length required length
1106     *
1107     * @return RandomAccess
1108     *
1109     * @throws IOException
1110     */

1111    public static RandomAccessRO createBufferedRO(int[] data, int off, int length) throws IOException JavaDoc {
1112        return createBufferedRO(new IntArrayBufferManager(data, off, length));
1113    }
1114
1115    /**
1116     * Create RandomAccess from int array
1117     *
1118     * @param data int array
1119     * @param off start offset
1120     * @param length required length
1121     *
1122     * @return RandomAccess
1123     *
1124     * @throws IOException
1125     */

1126    public static RandomAccess createBuffered(int[] data, int off, int length) throws IOException JavaDoc {
1127        return createBuffered(new IntArrayBufferManager(data, off, length));
1128    }
1129
1130    /**
1131     * Create RandomAccessRO from int array
1132     *
1133     * @param data int array
1134     *
1135     * @return RandomAccess
1136     *
1137     * @throws IOException
1138     */

1139    public static RandomAccessRO createBufferedRO(float[] data) throws IOException JavaDoc {
1140        return createBufferedRO(new FloatArrayBufferManager(data));
1141    }
1142
1143    /**
1144     * Create RandomAccess from int array
1145     *
1146     * @param data int array
1147     *
1148     * @return RandomAccess
1149     *
1150     * @throws IOException
1151     */

1152    public static RandomAccess createBuffered(float[] data) throws IOException JavaDoc {
1153        return createBuffered(new FloatArrayBufferManager(data));
1154    }
1155
1156    /**
1157     * Create RandomAccessRO from int array
1158     *
1159     * @param data int array
1160     * @param off start offset
1161     * @param length required length
1162     *
1163     * @return RandomAccess
1164     *
1165     * @throws IOException
1166     */

1167    public static RandomAccessRO createBufferedRO(float[] data, int off, int length) throws IOException JavaDoc {
1168        return createBufferedRO(new FloatArrayBufferManager(data, off, length));
1169    }
1170
1171    /**
1172     * Create RandomAccess from int array
1173     *
1174     * @param data int array
1175     * @param off start offset
1176     * @param length required length
1177     *
1178     * @return RandomAccess
1179     *
1180     * @throws IOException
1181     */

1182    public static RandomAccess createBuffered(float[] data, int off, int length) throws IOException JavaDoc {
1183        return createBuffered(new FloatArrayBufferManager(data, off, length));
1184    }
1185
1186    /**
1187     * Create RandomAccessRO from long array
1188     *
1189     * @param data long array
1190     *
1191     * @return RandomAccess
1192     *
1193     * @throws IOException
1194     */

1195    public static RandomAccessRO createBufferedRO(long[] data) throws IOException JavaDoc {
1196        return createBufferedRO(new LongArrayBufferManager(data));
1197    }
1198
1199    /**
1200     * Create RandomAccess from long array
1201     *
1202     * @param data long array
1203     *
1204     * @return RandomAccess
1205     *
1206     * @throws IOException
1207     */

1208    public static RandomAccess createBuffered(long[] data) throws IOException JavaDoc {
1209        return createBuffered(new LongArrayBufferManager(data));
1210    }
1211
1212    /**
1213     * Create RandomAccessRO from long array
1214     *
1215     * @param data long array
1216     * @param off start offset
1217     * @param length required length
1218     *
1219     * @return RandomAccess
1220     *
1221     * @throws IOException
1222     */

1223    public static RandomAccessRO createBufferedRO(long[] data, int off, int length) throws IOException JavaDoc {
1224        return createBufferedRO(new LongArrayBufferManager(data, off, length));
1225    }
1226
1227    /**
1228     * Create RandomAccess from long array
1229     *
1230     * @param data long array
1231     * @param off start offset
1232     * @param length required length
1233     *
1234     * @return RandomAccess
1235     *
1236     * @throws IOException
1237     */

1238    public static RandomAccess createBuffered(long[] data, int off, int length) throws IOException JavaDoc {
1239        return createBuffered(new LongArrayBufferManager(data, off, length));
1240    }
1241
1242    /**
1243     * Create RandomAccessRO from double array
1244     *
1245     * @param data double array
1246     *
1247     * @return RandomAccess
1248     *
1249     * @throws IOException
1250     */

1251    public static RandomAccessRO createBufferedRO(double[] data) throws IOException JavaDoc {
1252        return createBufferedRO(new DoubleArrayBufferManager(data));
1253    }
1254
1255    /**
1256     * Create RandomAccess from double array
1257     *
1258     * @param data double array
1259     *
1260     * @return RandomAccess
1261     *
1262     * @throws IOException
1263     */

1264    public static RandomAccess createBuffered(double[] data) throws IOException JavaDoc {
1265        return createBuffered(new DoubleArrayBufferManager(data));
1266    }
1267
1268    /**
1269     * Create RandomAccessRO from double array
1270     *
1271     * @param data double array
1272     * @param off start offset
1273     * @param length required length
1274     *
1275     * @return RandomAccess
1276     *
1277     * @throws IOException
1278     */

1279    public static RandomAccessRO createBufferedRO(double[] data, int off, int length) throws IOException JavaDoc {
1280        return createBufferedRO(new DoubleArrayBufferManager(data, off, length));
1281    }
1282
1283    /**
1284     * Create RandomAccess from double array
1285     *
1286     * @param data double array
1287     * @param off start offset
1288     * @param length required length
1289     *
1290     * @return RandomAccess
1291     *
1292     * @throws IOException
1293     */

1294    public static RandomAccess createBuffered(double[] data, int off, int length) throws IOException JavaDoc {
1295        return createBuffered(new DoubleArrayBufferManager(data, off, length));
1296    }
1297}
1298
Popular Tags