1 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 ; 53 import java.io.IOException ; 54 import java.io.InputStream ; 55 import java.io.RandomAccessFile ; 56 import java.io.OutputStream ; 57 import java.net.URL ; 58 59 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 90 public static RandomAccess createBuffered(MutableBufferManager sm, int byteOrder) throws IOException { 91 return new RandomAccessBuffer(sm, byteOrder); 92 } 93 94 108 public static RandomAccess createBuffered(MutableBufferManager sm) throws IOException { 109 return new RandomAccessBuffer(sm, BIG_ENDIAN); 110 } 111 112 127 public static RandomAccessRO createBufferedRO(BufferManager sm, int byteOrder) throws IOException { 128 return new RandomAccessBufferRO(sm, byteOrder); 129 } 130 131 145 public static RandomAccessRO createBufferedRO(BufferManager sm) throws IOException { 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 170 public static RandomAccess createBuffered(Buffer[] ds, int byteOrder) throws IOException { 171 return createBuffered(new DefaultBufferManager(ds), byteOrder); 172 } 173 174 189 public static RandomAccess createBuffered(Buffer[] ds) throws IOException { 190 return createBuffered(new DefaultBufferManager(ds), BIG_ENDIAN); 191 } 192 193 209 public static RandomAccessRO createBufferedRO(Buffer[] ds, int byteOrder) throws IOException { 210 return createBufferedRO(new DefaultBufferManager(ds), byteOrder); 211 } 212 213 228 public static RandomAccessRO createBufferedRO(Buffer[] ds) throws IOException { 229 return createBufferedRO(new DefaultBufferManager(ds), BIG_ENDIAN); 230 } 231 232 247 public static RandomAccessRO createBufferedRO(InputStream in, int byteOrder) throws IOException { 248 return new RandomAccessBufferRO(new InputStreamBufferManager(in), byteOrder); 249 } 250 251 265 public static RandomAccessRO createBufferedRO(InputStream in) throws IOException { 266 return createBufferedRO(in, BIG_ENDIAN); 267 } 268 269 270 281 public static RandomAccess create(File f, int byteOrder) throws IOException { 282 return create(new RandomAccessFile (f, "rw"), byteOrder); 283 } 284 285 295 public static RandomAccess create(File f) throws IOException { 296 return create(new RandomAccessFile (f, "rw"), BIG_ENDIAN); 297 } 298 299 310 public static RandomAccessRO createRO(File f, int byteOrder) throws IOException { 311 return createRO(new RandomAccessFile (f, "r"), byteOrder); 312 } 313 314 324 public static RandomAccessRO createRO(File f) throws IOException { 325 return createRO(new RandomAccessFile (f, "r"), BIG_ENDIAN); 326 } 327 328 338 public static RandomAccess create(String name, int byteOrder) throws IOException { 339 return create(new RandomAccessFile (name, "rw"), byteOrder); 340 } 341 342 351 public static RandomAccess create(String name) throws IOException { 352 return create(new RandomAccessFile (name, "rw"), BIG_ENDIAN); 353 } 354 355 365 public static RandomAccessRO createRO(String name, int byteOrder) throws IOException { 366 return createRO(new RandomAccessFile (name, "r"), byteOrder); 367 } 368 369 378 public static RandomAccessRO createRO(String name) throws IOException { 379 return createRO(new RandomAccessFile (name, "r"), BIG_ENDIAN); 380 } 381 382 393 public static RandomAccess create(File file, long offset, int byteOrder) throws IOException { 394 return create(new OffsetRandomAccessFile(file, "rw", offset), byteOrder); 395 } 396 397 407 public static RandomAccess create(File file, long offset) throws IOException { 408 return create(new OffsetRandomAccessFile(file, "rw", offset), BIG_ENDIAN); 409 } 410 411 423 public static RandomAccessRO createRO(File file, long offset, int byteOrder) throws IOException { 424 return createRO(new OffsetRandomAccessFile(file, "r", offset), byteOrder); 425 } 426 427 437 public static RandomAccessRO createRO(File file, long offset) throws IOException { 438 return createRO(new OffsetRandomAccessFile(file, "r", offset), BIG_ENDIAN); 439 } 440 441 453 public static RandomAccess create(File file, long offset, long length, int byteOrder) throws IOException { 454 return create(new OffsetRandomAccessFile(file, "rw", offset, length), byteOrder); 455 } 456 457 469 public static RandomAccess createBuffered(File file, long offset, long length, int byteOrder) throws IOException { 470 MutableBufferManager mbm = new MutableRAFBufferManager(new RandomAccessFile (file, "rw"), offset, (int) length); 471 return createBuffered(mbm, byteOrder); 472 } 473 474 485 public static RandomAccess create(File file, long offset, long length) throws IOException { 486 return create(new OffsetRandomAccessFile(file, "rw", offset, length), BIG_ENDIAN); 487 } 488 489 500 public static RandomAccess createBuffered(File file, long offset, long length) throws IOException { 501 return createBuffered(file, offset,length, BIG_ENDIAN); 502 } 503 504 516 public static RandomAccessRO createRO(File file, long offset, long length, int byteOrder) throws IOException { 517 return createRO(new OffsetRandomAccessFile(file, "r", offset, length), byteOrder); 518 } 519 520 532 public static RandomAccessRO createBufferedRO(File file, long offset, long length, int byteOrder) throws IOException { 533 BufferManager mbm = new RAFBufferManager(new RandomAccessFile (file, "r"), offset, (int) length); 534 return createBufferedRO(mbm, byteOrder); 535 } 536 537 548 public static RandomAccessRO createRO(File file, long offset, long length) throws IOException { 549 return createRO(new OffsetRandomAccessFile(file, "r", offset, length), BIG_ENDIAN); 550 } 551 552 563 public static RandomAccessRO createBufferedRO(File file, long offset, long length) throws IOException { 564 BufferManager mbm = new RAFBufferManager(new RandomAccessFile (file, "r"), offset, (int) length); 565 return createBufferedRO(mbm, BIG_ENDIAN); 566 } 567 568 580 public static RandomAccess create(String name, long offset, long length, int byteOrder) throws IOException { 581 return create(new OffsetRandomAccessFile(name, "rw", offset, length), byteOrder); 582 } 583 584 596 public static RandomAccess createBuffered(String name, long offset, long length, int byteOrder) throws IOException { 597 MutableBufferManager mbm = new MutableRAFBufferManager(new RandomAccessFile (name, "rw"), offset, (int) length); 598 return createBuffered(mbm, byteOrder); 599 } 600 601 612 public static RandomAccess create(String name, long offset, long length) throws IOException { 613 return create(new OffsetRandomAccessFile(name, "rw", offset, length), BIG_ENDIAN); 614 } 615 616 627 public static RandomAccess createBuffered(String name, long offset, long length) throws IOException { 628 MutableBufferManager mbm = new MutableRAFBufferManager(new RandomAccessFile (name, "rw"), offset, (int) length); 629 return createBuffered(mbm, BIG_ENDIAN); 630 } 631 632 644 public static RandomAccessRO createRO(String name, long offset, long length, int byteOrder) throws IOException { 645 return createRO(new OffsetRandomAccessFile(name, "r", offset, length), byteOrder); 646 } 647 648 660 public static RandomAccessRO createBufferedRO(String name, long offset, long length, int byteOrder) throws IOException { 661 BufferManager mbm = new RAFBufferManager(new RandomAccessFile (name, "r"), offset, (int) length); 662 return createBufferedRO(mbm, byteOrder); 663 } 664 665 676 public static RandomAccessRO createRO(String name, long offset, long length) throws IOException { 677 return createRO(new OffsetRandomAccessFile(name, "r", offset, length), BIG_ENDIAN); 678 } 679 680 691 public static RandomAccessRO createBufferedRO(String name, long offset, long length) throws IOException { 692 BufferManager mbm = new RAFBufferManager(new RandomAccessFile (name, "r"), offset, (int) length); 693 return createBufferedRO(mbm, BIG_ENDIAN); 694 } 695 696 704 public static RandomAccess create(RandomAccessFile raf, int byteOrder) throws IOException { 705 return new RandomAccessFileWrapper(raf, byteOrder); 706 } 707 708 716 public static RandomAccess createBuffered(RandomAccessFile raf, int byteOrder) throws IOException { 717 MutableBufferManager mbm = new MutableRAFBufferManager(raf, 0, (int) raf.length()); 718 return createBuffered(mbm, byteOrder); 719 } 720 721 728 public static RandomAccess create(RandomAccessFile raf) throws IOException { 729 return new RandomAccessFileWrapper(raf, BIG_ENDIAN); 730 } 731 732 739 public static RandomAccess createBuffered(RandomAccessFile raf) throws IOException { 740 MutableBufferManager mbm = new MutableRAFBufferManager(raf, 0, (int) raf.length()); 741 return createBuffered(mbm, BIG_ENDIAN); 742 } 743 744 751 public static RandomAccess createBuffered(OutputStream out) throws IOException { 752 MutableBufferManager mbm = new OutputStreamBufferManager(out); 753 return createBuffered(mbm, BIG_ENDIAN); 754 } 755 756 764 public static RandomAccessRO createRO(RandomAccessFile raf, int byteOrder) throws IOException { 765 return new RandomAccessFileWrapperRO(raf, byteOrder); 766 } 767 768 774 public static RandomAccessRO createBufferedRO(RandomAccessFile raf, int byteOrder) throws IOException { 775 BufferManager mbm = new RAFBufferManager(raf, 0, (int) raf.length()); 776 return createBufferedRO(mbm, byteOrder); 777 } 778 779 786 public static RandomAccessRO createRO(RandomAccessFile raf) throws IOException { 787 return new RandomAccessFileWrapperRO(raf, BIG_ENDIAN); 788 } 789 790 797 public static RandomAccessRO createBufferedRO(RandomAccessFile raf) throws IOException { 798 BufferManager mbm = new RAFBufferManager(raf, 0, (int) raf.length()); 799 return createBufferedRO(mbm, BIG_ENDIAN); 800 } 801 802 812 public static RandomAccess create(byte[] data, int byteOrder) throws IOException { 813 return new RandomAccessByteArray(data, byteOrder); 814 } 815 816 825 public static RandomAccess create(byte[] data) throws IOException { 826 return new RandomAccessByteArray(data, BIG_ENDIAN); 827 } 828 829 839 public static RandomAccessRO createRO(byte[] data, int byteOrder) throws IOException { 840 return new RandomAccessByteArrayRO(data, byteOrder); 841 } 842 843 852 public static RandomAccessRO createRO(byte[] data) throws IOException { 853 return new RandomAccessByteArrayRO(data, BIG_ENDIAN); 854 } 855 856 868 public static RandomAccess create(byte[] data, int off, int length, int byteOrder) throws IOException { 869 return new RandomAccessByteArray(data, off, length, byteOrder); 870 } 871 872 883 public static RandomAccess create(byte[] data, int off, int length) throws IOException { 884 return new RandomAccessByteArray(data, off, length, BIG_ENDIAN); 885 } 886 887 899 public static RandomAccessRO createRO(byte[] data, int off, int length, int byteOrder) throws IOException { 900 return new RandomAccessByteArrayRO(data, off, length, byteOrder); 901 } 902 903 914 public static RandomAccessRO createRO(byte[] data, int off, int length) throws IOException { 915 return new RandomAccessByteArrayRO(data, off, length, BIG_ENDIAN); 916 } 917 918 919 928 public static RandomAccessRO createBufferedRO(URL url) throws IOException { 929 return createBufferedRO(new HTTPBufferManager(url)); 930 } 931 932 943 public static RandomAccessRO createBufferedRO(RandomAccessRO ro, long offset, int length) throws IOException { 944 return createBufferedRO(new RABufferManager(ro, offset, length)); 945 } 946 947 958 public static RandomAccess createBuffered(RandomAccess ro, long offset, int length) throws IOException { 959 return createBuffered(new MutableRABufferManager(ro, offset, length)); 960 } 961 962 971 public static RandomAccessRO createBufferedRO(short[] data) throws IOException { 972 return createBufferedRO(new ShortArrayBufferManager(data)); 973 } 974 975 984 public static RandomAccess createBuffered(short[] data) throws IOException { 985 return createBuffered(new ShortArrayBufferManager(data)); 986 } 987 988 999 public static RandomAccessRO createBufferedRO(short[] data, int off, int length) throws IOException { 1000 return createBufferedRO(new ShortArrayBufferManager(data, off, length)); 1001 } 1002 1003 1014 public static RandomAccess createBuffered(short[] data, int off, int length) throws IOException { 1015 return createBuffered(new ShortArrayBufferManager(data, off, length)); 1016 } 1017 1018 1027 public static RandomAccessRO createBufferedRO(char[] data) throws IOException { 1028 return createBufferedRO(new CharArrayBufferManager(data)); 1029 } 1030 1031 1040 public static RandomAccess createBuffered(char[] data) throws IOException { 1041 return createBuffered(new CharArrayBufferManager(data)); 1042 } 1043 1044 1055 public static RandomAccessRO createBufferedRO(char[] data, int off, int length) throws IOException { 1056 return createBufferedRO(new CharArrayBufferManager(data, off, length)); 1057 } 1058 1059 1070 public static RandomAccess createBuffered(char[] data, int off, int length) throws IOException { 1071 return createBuffered(new CharArrayBufferManager(data, off, length)); 1072 } 1073 1074 1083 public static RandomAccessRO createBufferedRO(int[] data) throws IOException { 1084 return createBufferedRO(new IntArrayBufferManager(data)); 1085 } 1086 1087 1096 public static RandomAccess createBuffered(int[] data) throws IOException { 1097 return createBuffered(new IntArrayBufferManager(data)); 1098 } 1099 1100 1111 public static RandomAccessRO createBufferedRO(int[] data, int off, int length) throws IOException { 1112 return createBufferedRO(new IntArrayBufferManager(data, off, length)); 1113 } 1114 1115 1126 public static RandomAccess createBuffered(int[] data, int off, int length) throws IOException { 1127 return createBuffered(new IntArrayBufferManager(data, off, length)); 1128 } 1129 1130 1139 public static RandomAccessRO createBufferedRO(float[] data) throws IOException { 1140 return createBufferedRO(new FloatArrayBufferManager(data)); 1141 } 1142 1143 1152 public static RandomAccess createBuffered(float[] data) throws IOException { 1153 return createBuffered(new FloatArrayBufferManager(data)); 1154 } 1155 1156 1167 public static RandomAccessRO createBufferedRO(float[] data, int off, int length) throws IOException { 1168 return createBufferedRO(new FloatArrayBufferManager(data, off, length)); 1169 } 1170 1171 1182 public static RandomAccess createBuffered(float[] data, int off, int length) throws IOException { 1183 return createBuffered(new FloatArrayBufferManager(data, off, length)); 1184 } 1185 1186 1195 public static RandomAccessRO createBufferedRO(long[] data) throws IOException { 1196 return createBufferedRO(new LongArrayBufferManager(data)); 1197 } 1198 1199 1208 public static RandomAccess createBuffered(long[] data) throws IOException { 1209 return createBuffered(new LongArrayBufferManager(data)); 1210 } 1211 1212 1223 public static RandomAccessRO createBufferedRO(long[] data, int off, int length) throws IOException { 1224 return createBufferedRO(new LongArrayBufferManager(data, off, length)); 1225 } 1226 1227 1238 public static RandomAccess createBuffered(long[] data, int off, int length) throws IOException { 1239 return createBuffered(new LongArrayBufferManager(data, off, length)); 1240 } 1241 1242 1251 public static RandomAccessRO createBufferedRO(double[] data) throws IOException { 1252 return createBufferedRO(new DoubleArrayBufferManager(data)); 1253 } 1254 1255 1264 public static RandomAccess createBuffered(double[] data) throws IOException { 1265 return createBuffered(new DoubleArrayBufferManager(data)); 1266 } 1267 1268 1279 public static RandomAccessRO createBufferedRO(double[] data, int off, int length) throws IOException { 1280 return createBufferedRO(new DoubleArrayBufferManager(data, off, length)); 1281 } 1282 1283 1294 public static RandomAccess createBuffered(double[] data, int off, int length) throws IOException { 1295 return createBuffered(new DoubleArrayBufferManager(data, off, length)); 1296 } 1297} 1298 | Popular Tags |