Changeset 4900


Ignore:
Timestamp:
03/10/09 11:18:15 (11 years ago)
Author:
melissa
Message:

Added getHandle(String) method to Location, which returns an IRandomAccess. Most format writers now write to an IRandomAccess object instead of a RandomAccessFile; see ticket #354.

Location:
trunk/components
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/TiffTools.java

    r4899 r4900  
    17871787   */ 
    17881788  public static long writeImage(BufferedImage img, Hashtable ifd, 
    1789     OutputStream out, long offset, boolean last, boolean bigTiff) 
     1789    IRandomAccess out, long offset, boolean last, boolean bigTiff) 
    17901790    throws FormatException, IOException 
    17911791  { 
     
    19541954    } 
    19551955    out.write(extraArray); 
    1956     out.flush(); 
    19571956    return numBytes; 
    19581957  } 
  • trunk/components/bio-formats/src/loci/formats/out/APNGWriter.java

    r4550 r4900  
    4848  // -- Fields -- 
    4949 
    50   private RandomAccessFile out; 
     50  private IRandomAccess out; 
    5151  private int numFrames = 0; 
    5252  private long numFramesPointer = 0; 
     
    9090 
    9191    if (!initialized) { 
    92       out = new RandomAccessFile(currentId, "rw"); 
     92      out = Location.getHandle(currentId); 
    9393 
    9494      // write 8-byte PNG signature 
  • trunk/components/bio-formats/src/loci/formats/out/AVIWriter.java

    r4835 r4900  
    4646  // -- Fields -- 
    4747 
    48   private RandomAccessFile raFile; 
     48  private IRandomAccess out; 
    4949 
    5050  private int planesWritten = 0; 
     
    130130      bytesPerPixel = byteData.length; 
    131131 
    132       file = new File(currentId); 
    133       raFile = new RandomAccessFile(file, "rw"); 
    134       raFile.seek(raFile.length()); 
     132      out = Location.getHandle(currentId); 
     133      out.seek(out.length()); 
    135134      saveFileSize = 4; 
    136135      saveLIST1Size = 16; 
     
    164163      } 
    165164 
    166       if (raFile.length() == 0) { 
    167         DataTools.writeString(raFile, "RIFF"); // signature 
     165      if (out.length() == 0) { 
     166        DataTools.writeString(out, "RIFF"); // signature 
    168167        // Bytes 4 thru 7 contain the length of the file. This length does 
    169168        // not include bytes 0 thru 7. 
    170         DataTools.writeInt(raFile, 0, true); // for now write 0 for size 
    171         DataTools.writeString(raFile, "AVI "); // RIFF type 
     169        DataTools.writeInt(out, 0, true); // for now write 0 for size 
     170        DataTools.writeString(out, "AVI "); // RIFF type 
    172171        // Write the first LIST chunk, which contains 
    173172        // information on data decoding 
    174         DataTools.writeString(raFile, "LIST"); // CHUNK signature 
     173        DataTools.writeString(out, "LIST"); // CHUNK signature 
    175174        // Write the length of the LIST CHUNK not including the first 8 bytes 
    176175        // with LIST and size. Note that the end of the LIST CHUNK is followed 
    177176        // by JUNK. 
    178         DataTools.writeInt(raFile, (bytesPerPixel == 1) ? 1240 : 216, true); 
    179         DataTools.writeString(raFile, "hdrl"); // CHUNK type 
    180         DataTools.writeString(raFile, "avih"); // Write the avih sub-CHUNK 
     177        DataTools.writeInt(out, (bytesPerPixel == 1) ? 1240 : 216, true); 
     178        DataTools.writeString(out, "hdrl"); // CHUNK type 
     179        DataTools.writeString(out, "avih"); // Write the avih sub-CHUNK 
    181180 
    182181        // Write the length of the avih sub-CHUNK (38H) not including the 
    183182        // the first 8 bytes for avihSignature and the length 
    184         DataTools.writeInt(raFile, 0x38, true); 
     183        DataTools.writeInt(out, 0x38, true); 
    185184 
    186185        // dwMicroSecPerFrame - Write the microseconds per frame 
    187186        microSecPerFrame = (int) (1.0 / fps * 1.0e6); 
    188         DataTools.writeInt(raFile, microSecPerFrame, true); 
     187        DataTools.writeInt(out, microSecPerFrame, true); 
    189188 
    190189        // Write the maximum data rate of the file in bytes per second 
    191         DataTools.writeInt(raFile, 0, true); // dwMaxBytesPerSec 
    192  
    193         DataTools.writeInt(raFile, 0, true); // dwReserved1 - set to 0 
     190        DataTools.writeInt(out, 0, true); // dwMaxBytesPerSec 
     191 
     192        DataTools.writeInt(out, 0, true); // dwReserved1 - set to 0 
    194193        // dwFlags - just set the bit for AVIF_HASINDEX 
    195         DataTools.writeInt(raFile, 0x10, true); 
     194        DataTools.writeInt(out, 0x10, true); 
    196195 
    197196        // 10H AVIF_HASINDEX: The AVI file has an idx1 chunk containing 
     
    213212 
    214213        // dwTotalFrames - total frame number 
    215         DataTools.writeInt(raFile, zDim * tDim, true); 
     214        DataTools.writeInt(out, zDim * tDim, true); 
    216215 
    217216        // dwInitialFrames -Initial frame for interleaved files. 
    218217        // Noninterleaved files should specify 0. 
    219         DataTools.writeInt(raFile, 0, true); 
     218        DataTools.writeInt(out, 0, true); 
    220219 
    221220        // dwStreams - number of streams in the file - here 1 video and 
    222221        // zero audio. 
    223         DataTools.writeInt(raFile, 1, true); 
     222        DataTools.writeInt(out, 1, true); 
    224223 
    225224        // dwSuggestedBufferSize - Suggested buffer size for reading the file. 
    226225        // Generally, this size should be large enough to contain the largest 
    227226        // chunk in the file. 
    228         DataTools.writeInt(raFile, 0, true); 
     227        DataTools.writeInt(out, 0, true); 
    229228 
    230229        // dwWidth - image width in pixels 
    231         DataTools.writeInt(raFile, xDim - xPad, true); 
    232         DataTools.writeInt(raFile, yDim, true); // dwHeight - height in pixels 
     230        DataTools.writeInt(out, xDim - xPad, true); 
     231        DataTools.writeInt(out, yDim, true); // dwHeight - height in pixels 
    233232 
    234233        // dwReserved[4] - Microsoft says to set the following 4 values to 0. 
    235         DataTools.writeInt(raFile, 0, true); 
    236         DataTools.writeInt(raFile, 0, true); 
    237         DataTools.writeInt(raFile, 0, true); 
    238         DataTools.writeInt(raFile, 0, true); 
     234        DataTools.writeInt(out, 0, true); 
     235        DataTools.writeInt(out, 0, true); 
     236        DataTools.writeInt(out, 0, true); 
     237        DataTools.writeInt(out, 0, true); 
    239238 
    240239        // Write the Stream line header CHUNK 
    241         DataTools.writeString(raFile, "LIST"); 
     240        DataTools.writeString(out, "LIST"); 
    242241 
    243242        // Write the size of the first LIST subCHUNK not including the first 8 
     
    247246        // subCHUNK is followed by JUNK. 
    248247 
    249         DataTools.writeInt(raFile, (bytesPerPixel == 1) ? 1164 : 140 , true); 
    250         DataTools.writeString(raFile, "strl");   // Write the chunk type 
    251         DataTools.writeString(raFile, "strh"); // Write the strh sub-CHUNK 
    252         DataTools.writeInt(raFile, 56, true); // Write length of strh sub-CHUNK 
     248        DataTools.writeInt(out, (bytesPerPixel == 1) ? 1164 : 140 , true); 
     249        DataTools.writeString(out, "strl");   // Write the chunk type 
     250        DataTools.writeString(out, "strh"); // Write the strh sub-CHUNK 
     251        DataTools.writeInt(out, 56, true); // Write length of strh sub-CHUNK 
    253252 
    254253        // fccType - Write the type of data stream - here vids for video stream 
    255         DataTools.writeString(raFile, "vids"); 
     254        DataTools.writeString(out, "vids"); 
    256255 
    257256        // Write DIB for Microsoft Device Independent Bitmap. 
     
    259258        // sometimes used for uncompressed AVI videos: 'RGB ', 'RAW ', 
    260259        // 0x00000000 
    261         DataTools.writeString(raFile, "DIB "); 
    262  
    263         DataTools.writeInt(raFile, 0, true); // dwFlags 
     260        DataTools.writeString(out, "DIB "); 
     261 
     262        DataTools.writeInt(out, 0, true); // dwFlags 
    264263 
    265264        // 0x00000001 AVISF_DISABLED The stram data should be rendered only when 
     
    272271        // multiple audio streams, the one with the highest priority might be 
    273272        // the default one. 
    274         DataTools.writeInt(raFile, 0, true); 
     273        DataTools.writeInt(out, 0, true); 
    275274 
    276275        // dwInitialFrames - Specifies how far audio data is skewed ahead of 
     
    279278        // file prior to the initial frame of the AVI sequence. 
    280279        // Noninterleaved files should use zero. 
    281         DataTools.writeInt(raFile, 0, true); 
     280        DataTools.writeInt(out, 0, true); 
    282281 
    283282        // rate/scale = samples/second 
    284         DataTools.writeInt(raFile, 1, true); // dwScale 
     283        DataTools.writeInt(out, 1, true); // dwScale 
    285284 
    286285        //  dwRate - frame rate for video streams 
    287         DataTools.writeInt(raFile, fps, true); 
     286        DataTools.writeInt(out, fps, true); 
    288287 
    289288        // dwStart - this field is usually set to zero 
    290         DataTools.writeInt(raFile, 0, true); 
     289        DataTools.writeInt(out, 0, true); 
    291290 
    292291        // dwLength - playing time of AVI file as defined by scale and rate 
    293292        // Set equal to the number of frames 
    294         DataTools.writeInt(raFile, tDim * zDim, true); 
     293        DataTools.writeInt(out, tDim * zDim, true); 
    295294 
    296295        // dwSuggestedBufferSize - Suggested buffer size for reading the stream. 
    297296        // Typically, this contains a value corresponding to the largest chunk 
    298297        // in a stream. 
    299         DataTools.writeInt(raFile, 0, true); 
     298        DataTools.writeInt(out, 0, true); 
    300299 
    301300        // dwQuality - encoding quality given by an integer between 0 and 
    302301        // 10,000. If set to -1, drivers use the default quality value. 
    303         DataTools.writeInt(raFile, -1, true); 
     302        DataTools.writeInt(out, -1, true); 
    304303 
    305304        // dwSampleSize # 
     
    308307        // separate chunk. If nonzero, then multiple samples of data can be 
    309308        // grouped into a single chunk within the file. 
    310         DataTools.writeInt(raFile, 0, true); 
     309        DataTools.writeInt(out, 0, true); 
    311310 
    312311        // rcFrame - Specifies the destination rectangle for a text or video 
     
    318317        // The upper-left corner of the destination rectangle is relative to the 
    319318        // upper-left corner of the movie rectangle. 
    320         DataTools.writeShort(raFile, (short) 0, true); // left 
    321         DataTools.writeShort(raFile, (short) 0, true); // top 
    322         DataTools.writeShort(raFile, (short) 0, true); // right 
    323         DataTools.writeShort(raFile, (short) 0, true); // bottom 
     319        DataTools.writeShort(out, (short) 0, true); // left 
     320        DataTools.writeShort(out, (short) 0, true); // top 
     321        DataTools.writeShort(out, (short) 0, true); // right 
     322        DataTools.writeShort(out, (short) 0, true); // bottom 
    324323 
    325324        // Write the size of the stream format CHUNK not including the first 8 
    326325        // bytes for strf and the size. Note that the end of the stream format 
    327326        // CHUNK is followed by strn. 
    328         DataTools.writeString(raFile, "strf"); // Write the stream format chunk 
     327        DataTools.writeString(out, "strf"); // Write the stream format chunk 
    329328 
    330329        // write the strf CHUNK size 
    331         DataTools.writeInt(raFile, (bytesPerPixel == 1) ? 1068 : 44, true); 
     330        DataTools.writeInt(out, (bytesPerPixel == 1) ? 1068 : 44, true); 
    332331 
    333332        // Applications should use this size to determine which BITMAPINFO 
     
    335334        // biSize- Write header size of BITMAPINFO header structure 
    336335 
    337         DataTools.writeInt(raFile, 40, true); 
     336        DataTools.writeInt(out, 40, true); 
    338337 
    339338        // biWidth - image width in pixels 
    340         DataTools.writeInt(raFile, xDim, true); 
     339        DataTools.writeInt(out, xDim, true); 
    341340 
    342341        // biHeight - image height in pixels. If height is positive, the bitmap 
     
    345344        // the upper left corner. This negative sign feature is supported by the 
    346345        // Windows Media Player, but it is not supported by PowerPoint. 
    347         DataTools.writeInt(raFile, yDim, true); 
     346        DataTools.writeInt(out, yDim, true); 
    348347 
    349348        // biPlanes - number of color planes in which the data is stored 
    350349        // This must be set to 1. 
    351         DataTools.writeShort(raFile, 1, true); 
     350        DataTools.writeShort(out, 1, true); 
    352351 
    353352        int bitsPerPixel = (bytesPerPixel == 3) ? 24 : 8; 
     
    355354        // biBitCount - number of bits per pixel # 
    356355        // 0L for BI_RGB, uncompressed data as bitmap 
    357         DataTools.writeShort(raFile, (short) bitsPerPixel, true); 
     356        DataTools.writeShort(out, (short) bitsPerPixel, true); 
    358357 
    359358        //writeInt(bytesPerPixel * xDim * yDim * zDim * tDim); // biSizeImage # 
    360         DataTools.writeInt(raFile, 0, true); // biSizeImage # 
    361         DataTools.writeInt(raFile, 0, true); // biCompression - compression type 
     359        DataTools.writeInt(out, 0, true); // biSizeImage # 
     360        DataTools.writeInt(out, 0, true); // biCompression - compression type 
    362361        // biXPelsPerMeter - horizontal resolution in pixels 
    363         DataTools.writeInt(raFile, 0, true); 
     362        DataTools.writeInt(out, 0, true); 
    364363        // biYPelsPerMeter - vertical resolution in pixels per meter 
    365         DataTools.writeInt(raFile, 0, true); 
     364        DataTools.writeInt(out, 0, true); 
    366365 
    367366        int nColors = lut == null ? 0 : 256; 
    368         DataTools.writeInt(raFile, nColors, true); 
     367        DataTools.writeInt(out, nColors, true); 
    369368 
    370369        // biClrImportant - specifies that the first x colors of the color table 
     
    373372        // manner. When this field is set to zero, all the colors are important, 
    374373        // or, rather, their relative importance has not been computed. 
    375         DataTools.writeInt(raFile, 0, true); 
     374        DataTools.writeInt(out, 0, true); 
    376375 
    377376        // Write the LUTa.getExtents()[1] color table entries here. They are 
     
    380379          if (lut != null) { 
    381380            for (int i=0; i<256; i++) { 
    382               raFile.write(lut[2][i]); 
    383               raFile.write(lut[1][i]); 
    384               raFile.write(lut[0][i]); 
    385               raFile.write(lut[3][i]); 
     381              out.write(lut[2][i]); 
     382              out.write(lut[1][i]); 
     383              out.write(lut[0][i]); 
     384              out.write(lut[3][i]); 
    386385            } 
    387386          } 
     
    394393              lutWrite[4*i+3] = 0; 
    395394            } 
    396             raFile.write(lutWrite); 
     395            out.write(lutWrite); 
    397396          } 
    398397        } 
    399398 
    400         raFile.seek(savestrfSize); 
    401         DataTools.writeInt(raFile, 
     399        out.seek(savestrfSize); 
     400        DataTools.writeInt(out, 
    402401          (int) (savestrnPos - (savestrfSize + 4)), true); 
    403         raFile.seek(savestrnPos); 
     402        out.seek(savestrnPos); 
    404403 
    405404        // Use strn to provide zero terminated text string describing the stream 
    406         DataTools.writeString(raFile, "strn"); 
    407         DataTools.writeInt(raFile, 16, true); // Write length of strn sub-CHUNK 
    408         DataTools.writeString(raFile, "FileAVI write  "); 
    409  
    410         raFile.seek(saveLIST1Size); 
    411         DataTools.writeInt(raFile, 
     405        DataTools.writeString(out, "strn"); 
     406        DataTools.writeInt(out, 16, true); // Write length of strn sub-CHUNK 
     407        DataTools.writeString(out, "FileAVI write  "); 
     408 
     409        out.seek(saveLIST1Size); 
     410        DataTools.writeInt(out, 
    412411          (int) (saveJUNKsignature - (saveLIST1Size + 4)), true); 
    413         raFile.seek(saveLIST1subSize); 
    414         DataTools.writeInt(raFile, 
     412        out.seek(saveLIST1subSize); 
     413        DataTools.writeInt(out, 
    415414          (int) (saveJUNKsignature - (saveLIST1subSize + 4)), true); 
    416         raFile.seek(saveJUNKsignature); 
     415        out.seek(saveJUNKsignature); 
    417416 
    418417        // write a JUNK CHUNK for padding 
    419         DataTools.writeString(raFile, "JUNK"); 
     418        DataTools.writeString(out, "JUNK"); 
    420419        paddingBytes = (int) (4084 - (saveJUNKsignature + 8)); 
    421         DataTools.writeInt(raFile, paddingBytes, true); 
     420        DataTools.writeInt(out, paddingBytes, true); 
    422421        for (int i=0; i<paddingBytes/2; i++) { 
    423           DataTools.writeShort(raFile, (short) 0, true); 
     422          DataTools.writeShort(out, (short) 0, true); 
    424423        } 
    425424 
    426425        // Write the second LIST chunk, which contains the actual data 
    427         DataTools.writeString(raFile, "LIST"); 
     426        DataTools.writeString(out, "LIST"); 
    428427 
    429428        // Write the length of the LIST CHUNK not including the first 8 bytes 
    430429        // with LIST and size. The end of the second LIST CHUNK is followed by 
    431430        // idx1. 
    432         saveLIST2Size = raFile.getFilePointer(); 
    433  
    434         DataTools.writeInt(raFile, 0, true);  // For now write 0 
    435         DataTools.writeString(raFile, "movi"); // Write CHUNK type 'movi' 
     431        saveLIST2Size = out.getFilePointer(); 
     432 
     433        DataTools.writeInt(out, 0, true);  // For now write 0 
     434        DataTools.writeString(out, "movi"); // Write CHUNK type 'movi' 
    436435      } 
    437436    } 
     
    444443    int height = byteData[0].length / width; 
    445444 
    446     raFile.write(dataSignature); 
    447     savedbLength.add(new Long(raFile.getFilePointer())); 
     445    out.write(dataSignature); 
     446    savedbLength.add(new Long(out.getFilePointer())); 
    448447    // Write the data length 
    449448 
    450     DataTools.writeInt(raFile, bytesPerPixel * xDim * yDim, true); 
     449    DataTools.writeInt(out, bytesPerPixel * xDim * yDim, true); 
    451450 
    452451    if (bytesPerPixel == 1) { 
    453452      for (int i=(height-1); i>=0; i--) { 
    454         raFile.write(byteData[0], i*width, width); 
    455         for (int j=0; j<xPad; j++) raFile.write(0); 
     453        out.write(byteData[0], i*width, width); 
     454        for (int j=0; j<xPad; j++) out.write(0); 
    456455      } 
    457456    } 
     
    469468        next += xPad * byteData.length; 
    470469      } 
    471       raFile.write(buf); 
     470      out.write(buf); 
    472471      buf = null; 
    473472    } 
     
    478477      // Write the idx1 CHUNK 
    479478      // Write the 'idx1' signature 
    480       idx1Pos = raFile.getFilePointer(); 
    481       raFile.seek(saveLIST2Size); 
    482       DataTools.writeInt(raFile, (int) (idx1Pos - (saveLIST2Size + 4)), true); 
    483       raFile.seek(idx1Pos); 
    484       DataTools.writeString(raFile, "idx1"); 
    485  
    486       saveidx1Length = raFile.getFilePointer(); 
     479      idx1Pos = out.getFilePointer(); 
     480      out.seek(saveLIST2Size); 
     481      DataTools.writeInt(out, (int) (idx1Pos - (saveLIST2Size + 4)), true); 
     482      out.seek(idx1Pos); 
     483      DataTools.writeString(out, "idx1"); 
     484 
     485      saveidx1Length = out.getFilePointer(); 
    487486 
    488487      // Write the length of the idx1 CHUNK not including the idx1 signature 
    489       DataTools.writeInt(raFile, 4 + (planesWritten*16), true); 
     488      DataTools.writeInt(out, 4 + (planesWritten*16), true); 
    490489 
    491490      for (z=0; z<planesWritten; z++) { 
    492491        // In the ckid field write the 4 character code to identify the chunk 
    493492        // 00db or 00dc 
    494         raFile.write(dataSignature); 
     493        out.write(dataSignature); 
    495494        // Write the flags - select AVIIF_KEYFRAME 
    496         if (z == 0) DataTools.writeInt(raFile, 0x10, true); 
    497         else DataTools.writeInt(raFile, 0x00, true); 
     495        if (z == 0) DataTools.writeInt(out, 0x10, true); 
     496        else DataTools.writeInt(out, 0x00, true); 
    498497 
    499498        // AVIIF_KEYFRAME 0x00000010L 
     
    506505        // AVIIF_TWOCC 2L 
    507506        // AVIIF_COMPUSE 0x0FFF0000L These bits are for compressor use. 
    508         DataTools.writeInt(raFile, (int) (((Long) 
     507        DataTools.writeInt(out, (int) (((Long) 
    509508          savedbLength.get(z)).longValue() - 4 - savemovi), true); 
    510509 
     
    512511        // CHUNK. Write the length of the relevant CHUNK. Note that this length 
    513512        // is also written at savedbLength 
    514         DataTools.writeInt(raFile, bytesPerPixel*xDim*yDim, true); 
     513        DataTools.writeInt(out, bytesPerPixel*xDim*yDim, true); 
    515514      } 
    516       endPos = raFile.getFilePointer(); 
    517       raFile.seek(saveFileSize); 
    518       DataTools.writeInt(raFile, (int) (endPos - (saveFileSize + 4)), true); 
    519  
    520       raFile.seek(saveidx1Length); 
    521       DataTools.writeInt(raFile, (int) (endPos - (saveidx1Length + 4)), true); 
     515      endPos = out.getFilePointer(); 
     516      out.seek(saveFileSize); 
     517      DataTools.writeInt(out, (int) (endPos - (saveFileSize + 4)), true); 
     518 
     519      out.seek(saveidx1Length); 
     520      DataTools.writeInt(out, (int) (endPos - (saveidx1Length + 4)), true); 
    522521 
    523522      // write the total number of planes 
    524       raFile.seek(frameOffset); 
    525       DataTools.writeInt(raFile, planesWritten, true); 
    526       raFile.seek(frameOffset2); 
    527       DataTools.writeInt(raFile, planesWritten, true); 
    528  
    529       raFile.close(); 
     523      out.seek(frameOffset); 
     524      DataTools.writeInt(out, planesWritten, true); 
     525      out.seek(frameOffset2); 
     526      DataTools.writeInt(out, planesWritten, true); 
     527 
     528      out.close(); 
    530529    } 
    531530  } 
     
    543542  /* @see loci.formats.IFormatHandler#close() */ 
    544543  public void close() throws IOException { 
    545     if (raFile != null) raFile.close(); 
    546     raFile = null; 
     544    if (out != null) out.close(); 
     545    out = null; 
    547546    currentId = null; 
    548547    initialized = false; 
  • trunk/components/bio-formats/src/loci/formats/out/EPSWriter.java

    r4705 r4900  
    4242 
    4343  /** Current file. */ 
    44   protected RandomAccessFile out; 
     44  protected IRandomAccess out; 
    4545 
    4646  // -- Constructor -- 
     
    6060    } 
    6161 
    62     out = new RandomAccessFile(currentId, "rw"); 
     62    out = Location.getHandle(currentId); 
    6363 
    6464    BufferedImage img = AWTImageTools.makeBuffered(image, cm); 
     
    7878    // write the header 
    7979 
    80     DataTools.writeString(out, "%!PS-Adobe-2.0 EPSF-1.2\n"); 
    81     DataTools.writeString(out, "%%Title: " + currentId + "\n"); 
    82     DataTools.writeString(out, "%%Creator: LOCI Bio-Formats\n"); 
    83     DataTools.writeString(out, "%%Pages: 1\n"); 
    84     DataTools.writeString(out, "%%BoundingBox: 0 0 " + width + 
    85       " " + height + "\n"); 
    86     DataTools.writeString(out, "%%EndComments\n\n"); 
     80    out.writeBytes("%!PS-Adobe-2.0 EPSF-1.2\n"); 
     81    out.writeBytes("%%Title: " + currentId + "\n"); 
     82    out.writeBytes("%%Creator: LOCI Bio-Formats\n"); 
     83    out.writeBytes("%%Pages: 1\n"); 
     84    out.writeBytes("%%BoundingBox: 0 0 " + width + " " + height + "\n"); 
     85    out.writeBytes("%%EndComments\n\n"); 
    8786 
    88     DataTools.writeString(out, "/ld {load def} bind def\n"); 
    89     DataTools.writeString(out, "/s /stroke ld /f /fill ld /m /moveto ld /l " + 
     87    out.writeBytes("/ld {load def} bind def\n"); 
     88    out.writeBytes("/s /stroke ld /f /fill ld /m /moveto ld /l " + 
    9089      "/lineto ld /c /curveto ld /rgb {255 div 3 1 roll 255 div 3 1 " + 
    9190      "roll 255 div 3 1 roll setrgbcolor} def\n"); 
    92     DataTools.writeString(out, "0 0 translate\n"); 
    93     DataTools.writeString(out, ((float) width) + " " + ((float) height) + 
    94       " scale\n"); 
    95     DataTools.writeString(out, "/picstr 40 string def\n"); 
     91    out.writeBytes("0 0 translate\n"); 
     92    out.writeBytes(((float) width) + " " + ((float) height) + " scale\n"); 
     93    out.writeBytes("/picstr 40 string def\n"); 
    9694    if (byteData.length == 1) { 
    97       DataTools.writeString(out, width + " " + height + " 8 [" + width + 
    98         " 0 0 " + (-1*height) + " 0 " + height + "] {currentfile picstr " + 
     95      out.writeBytes(width + " " + height + " 8 [" + width + " 0 0 " + 
     96        (-1*height) + " 0 " + height + "] {currentfile picstr " + 
    9997        "readhexstring pop} image\n"); 
    10098 
     
    109107          if (s.length() > 1) s = s.substring(s.length() - 2); 
    110108          else s = "0" + s; 
    111           DataTools.writeString(out, s); 
     109          out.writeBytes(s); 
    112110          charCount++; 
    113111          if (charCount == 40) { 
    114             DataTools.writeString(out, "\n"); 
     112            out.writeBytes("\n"); 
    115113            charCount = 0; 
    116114          } 
     
    119117    } 
    120118    else { 
    121       DataTools.writeString(out, width + " " + height + " 8 [" + width + 
    122         " 0 0 " + (-1*height) + " 0 " + height + "] {currentfile picstr " + 
     119      out.writeBytes(width + " " + height + " 8 [" + width + " 0 0 " + 
     120        (-1*height) + " 0 " + height + "] {currentfile picstr " + 
    123121        "readhexstring pop} false 3 colorimage\n"); 
    124122 
     
    133131          if (s.length() > 1) s = s.substring(s.length() - 2); 
    134132          else s = "0" + s; 
    135           DataTools.writeString(out, s); 
     133          out.writeBytes(s); 
    136134          charCount++; 
    137135          if (charCount == 40) { 
    138             DataTools.writeString(out, "\n"); 
     136            out.writeBytes("\n"); 
    139137            charCount = 0; 
    140138          } 
     
    145143    // write footer 
    146144 
    147     DataTools.writeString(out, "showpage\n"); 
     145    out.writeBytes("showpage\n"); 
    148146    out.close(); 
    149147  } 
  • trunk/components/bio-formats/src/loci/formats/out/ICSWriter.java

    r4550 r4900  
    4545  // -- Fields -- 
    4646 
    47   private RandomAccessFile out; 
     47  private IRandomAccess out; 
    4848 
    4949  // -- Constructor -- 
     
    6767    if (!initialized) { 
    6868      initialized = true; 
    69       out = new RandomAccessFile(currentId, "rw"); 
     69      out = Location.getHandle(currentId); 
    7070      out.writeBytes("\t\n"); 
    7171      out.writeBytes("ics_version\t2.0\n"); 
  • trunk/components/bio-formats/src/loci/formats/out/JPEG2000Writer.java

    r4705 r4900  
    4444  // -- Fields -- 
    4545 
    46   private RandomAccessFile out; 
     46  private IRandomAccess out; 
    4747 
    4848  // -- Constructor -- 
     
    8383    int bytesPerPixel = byteData[0].length / (img.getWidth() * img.getHeight()); 
    8484 
    85     out = new RandomAccessFile(currentId, "rw"); 
     85    out = Location.getHandle(currentId); 
    8686 
    8787    CodecOptions options = new CodecOptions(); 
  • trunk/components/bio-formats/src/loci/formats/out/OMEXMLWriter.java

    r4705 r4900  
    4747 
    4848  private Vector xmlFragments; 
    49   private RandomAccessFile out; 
     49  private IRandomAccess out; 
    5050  private String currentFragment; 
    5151 
     
    7676    MetadataRetrieve retrieve = getMetadataRetrieve(); 
    7777    if (!initialized) { 
    78       out = new RandomAccessFile(currentId, "rw"); 
     78      out = Location.getHandle(currentId); 
    7979 
    8080      String xml = MetadataTools.getOMEXML(retrieve); 
  • trunk/components/bio-formats/src/loci/formats/out/QTWriter.java

    r4820 r4900  
    8585 
    8686  /** Current file. */ 
    87   protected RandomAccessFile out; 
     87  protected IRandomAccess out; 
    8888 
    8989  /** The codec to use. */ 
     
    233233 
    234234      offsets = new Vector(); 
    235       out = new RandomAccessFile(currentId, "rw"); 
     235      out = Location.getHandle(currentId); 
    236236      created = (int) System.currentTimeMillis(); 
    237237      numWritten = 0; 
     
    243243 
    244244        DataTools.writeInt(out, 8, false); 
    245         DataTools.writeString(out, "wide"); 
     245        out.writeBytes("wide"); 
    246246 
    247247        DataTools.writeInt(out, numBytes + 8, false); 
    248         DataTools.writeString(out, "mdat"); 
     248        out.writeBytes("mdat"); 
    249249      } 
    250250      else { 
     
    302302      int atomLength = 685 + 8*numWritten; 
    303303      DataTools.writeInt(out, atomLength, false); 
    304       DataTools.writeString(out, "moov"); 
     304      out.writeBytes("moov"); 
    305305 
    306306      // -- write mvhd atom -- 
    307307 
    308308      DataTools.writeInt(out, 108, false); 
    309       DataTools.writeString(out, "mvhd"); 
     309      out.writeBytes("mvhd"); 
    310310      DataTools.writeShort(out, 0, false); // version 
    311311      DataTools.writeShort(out, 0, false); // flags 
     
    342342      atomLength -= 116; 
    343343      DataTools.writeInt(out, atomLength, false); 
    344       DataTools.writeString(out, "trak"); 
     344      out.writeBytes("trak"); 
    345345 
    346346      // -- write tkhd atom -- 
     
    382382 
    383383      DataTools.writeInt(out, 36, false); 
    384       DataTools.writeString(out, "edts"); 
     384      out.writeBytes("edts"); 
    385385 
    386386      // -- write elst atom -- 
    387387 
    388388      DataTools.writeInt(out, 28, false); 
    389       DataTools.writeString(out, "elst"); 
     389      out.writeBytes("elst"); 
    390390 
    391391      DataTools.writeShort(out, 0, false); // version 
     
    401401      atomLength -= 136; 
    402402      DataTools.writeInt(out, atomLength, false); 
    403       DataTools.writeString(out, "mdia"); 
     403      out.writeBytes("mdia"); 
    404404 
    405405      // -- write mdhd atom -- 
    406406 
    407407      DataTools.writeInt(out, 32, false); 
    408       DataTools.writeString(out, "mdhd"); 
     408      out.writeBytes("mdhd"); 
    409409 
    410410      DataTools.writeShort(out, 0, false); // version 
     
    420420 
    421421      DataTools.writeInt(out, 58, false); 
    422       DataTools.writeString(out, "hdlr"); 
    423  
    424       DataTools.writeShort(out, 0, false); // version 
    425       DataTools.writeShort(out, 0, false); // flags 
    426       DataTools.writeString(out, "mhlr"); 
    427       DataTools.writeString(out, "vide"); 
    428       DataTools.writeString(out, "appl"); 
     422      out.writeBytes("hdlr"); 
     423 
     424      DataTools.writeShort(out, 0, false); // version 
     425      DataTools.writeShort(out, 0, false); // flags 
     426      out.writeBytes("mhlr"); 
     427      out.writeBytes("vide"); 
     428      out.writeBytes("appl"); 
    429429      out.write(new byte[] {16, 0, 0, 0, 0, 1, 1, 11, 25}); 
    430       DataTools.writeString(out, "Apple Video Media Handler"); 
     430      out.writeBytes("Apple Video Media Handler"); 
    431431 
    432432      // -- write minf atom -- 
     
    434434      atomLength -= 98; 
    435435      DataTools.writeInt(out, atomLength, false); 
    436       DataTools.writeString(out, "minf"); 
     436      out.writeBytes("minf"); 
    437437 
    438438      // -- write vmhd atom -- 
    439439 
    440440      DataTools.writeInt(out, 20, false); 
    441       DataTools.writeString(out, "vmhd"); 
     441      out.writeBytes("vmhd"); 
    442442 
    443443      DataTools.writeShort(out, 0, false); // version 
     
    451451 
    452452      DataTools.writeInt(out, 57, false); 
    453       DataTools.writeString(out, "hdlr"); 
    454  
    455       DataTools.writeShort(out, 0, false); // version 
    456       DataTools.writeShort(out, 0, false); // flags 
    457       DataTools.writeString(out, "dhlr"); 
    458       DataTools.writeString(out, "alis"); 
    459       DataTools.writeString(out, "appl"); 
     453      out.writeBytes("hdlr"); 
     454 
     455      DataTools.writeShort(out, 0, false); // version 
     456      DataTools.writeShort(out, 0, false); // flags 
     457      out.writeBytes("dhlr"); 
     458      out.writeBytes("alis"); 
     459      out.writeBytes("appl"); 
    460460      out.write(new byte[] {16, 0, 0, 1, 0, 1, 1, 31, 24}); 
    461       DataTools.writeString(out, "Apple Alias Data Handler"); 
     461      out.writeBytes("Apple Alias Data Handler"); 
    462462 
    463463      // -- write dinf atom -- 
    464464 
    465465      DataTools.writeInt(out, 36, false); 
    466       DataTools.writeString(out, "dinf"); 
     466      out.writeBytes("dinf"); 
    467467 
    468468      // -- write dref atom -- 
    469469 
    470470      DataTools.writeInt(out, 28, false); 
    471       DataTools.writeString(out, "dref"); 
     471      out.writeBytes("dref"); 
    472472 
    473473      DataTools.writeShort(out, 0, false); // version 
     
    476476      DataTools.writeShort(out, 1, false); // flags 2 
    477477      out.write(new byte[] {0, 0, 0, 12}); 
    478       DataTools.writeString(out, "alis"); 
     478      out.writeBytes("alis"); 
    479479      DataTools.writeShort(out, 0, false); // version 3 
    480480      DataTools.writeShort(out, 1, false); // flags 3 
     
    484484      atomLength -= 121; 
    485485      DataTools.writeInt(out, atomLength, false); 
    486       DataTools.writeString(out, "stbl"); 
     486      out.writeBytes("stbl"); 
    487487 
    488488      // -- write stsd atom -- 
    489489 
    490490      DataTools.writeInt(out, 118, false); 
    491       DataTools.writeString(out, "stsd"); 
     491      out.writeBytes("stsd"); 
    492492 
    493493      DataTools.writeShort(out, 0, false); // version 
     
    495495      DataTools.writeInt(out, 1, false); // number of entries in the table 
    496496      out.write(new byte[] {0, 0, 0, 102}); 
    497       DataTools.writeString(out, "raw "); // codec 
     497      out.writeBytes("raw "); // codec 
    498498      out.write(new byte[] {0, 0, 0, 0, 0, 0});  // reserved 
    499499      DataTools.writeShort(out, 1, false); // data reference 
    500500      DataTools.writeShort(out, 1, false); // version 
    501501      DataTools.writeShort(out, 1, false); // revision 
    502       DataTools.writeString(out, "appl"); 
     502      out.writeBytes("appl"); 
    503503      DataTools.writeInt(out, 0, false); // temporal quality 
    504504      DataTools.writeInt(out, 768, false); // spatial quality 
     
    510510      DataTools.writeShort(out, 1, false); // frames per sample 
    511511      DataTools.writeShort(out, 12, false); // length of compressor name 
    512       DataTools.writeString(out, "Uncompressed"); // compressor name 
     512      out.writeBytes("Uncompressed"); // compressor name 
    513513      DataTools.writeInt(out, bitsPerPixel, false); // unknown 
    514514      DataTools.writeInt(out, bitsPerPixel, false); // unknown 
     
    524524 
    525525      DataTools.writeInt(out, 24, false); 
    526       DataTools.writeString(out, "stts"); 
     526      out.writeBytes("stts"); 
    527527 
    528528      DataTools.writeShort(out, 0, false); // version 
     
    535535 
    536536      DataTools.writeInt(out, 28, false); 
    537       DataTools.writeString(out, "stsc"); 
     537      out.writeBytes("stsc"); 
    538538 
    539539      DataTools.writeShort(out, 0, false); // version 
     
    547547 
    548548      DataTools.writeInt(out, 20 + 4*numWritten, false); 
    549       DataTools.writeString(out, "stsz"); 
     549      out.writeBytes("stsz"); 
    550550 
    551551      DataTools.writeShort(out, 0, false); // version 
     
    562562 
    563563      DataTools.writeInt(out, 16 + 4*numWritten, false); 
    564       DataTools.writeString(out, "stco"); 
     564      out.writeBytes("stco"); 
    565565 
    566566      DataTools.writeShort(out, 0, false); // version 
  • trunk/components/bio-formats/src/loci/formats/out/TiffWriter.java

    r4783 r4900  
    4747 
    4848  /** Current output stream. */ 
    49   protected BufferedOutputStream out; 
     49  protected IRandomAccess out; 
    5050 
    5151  /** Image counts for each open series. */ 
     
    100100      imageCounts = new Vector(); 
    101101      initialized = true; 
    102       out = 
    103         new BufferedOutputStream(new FileOutputStream(currentId, true), 4096); 
     102      out = Location.getHandle(currentId); 
    104103 
    105104      RandomAccessStream tmp = new RandomAccessStream(currentId); 
    106105      if (tmp.length() == 0) { 
    107106        // write TIFF header 
    108         DataOutputStream dataOut = new DataOutputStream(out); 
    109107        if (littleEndian) { 
    110           dataOut.writeByte(TiffTools.LITTLE); 
    111           dataOut.writeByte(TiffTools.LITTLE); 
     108          out.writeByte(TiffTools.LITTLE); 
     109          out.writeByte(TiffTools.LITTLE); 
    112110        } 
    113111        else { 
    114           dataOut.writeByte(TiffTools.BIG); 
    115           dataOut.writeByte(TiffTools.BIG); 
     112          out.writeByte(TiffTools.BIG); 
     113          out.writeByte(TiffTools.BIG); 
    116114        } 
    117115        if (isBigTiff) { 
    118           DataTools.writeShort(dataOut, TiffTools.BIG_TIFF_MAGIC_NUMBER, 
     116          DataTools.writeShort(out, TiffTools.BIG_TIFF_MAGIC_NUMBER, 
    119117            littleEndian); 
    120118        } 
    121119        else { 
    122           DataTools.writeShort(dataOut, TiffTools.MAGIC_NUMBER, littleEndian); 
    123         } 
    124         DataTools.writeInt(dataOut, 8, littleEndian); // offset to first IFD 
     120          DataTools.writeShort(out, TiffTools.MAGIC_NUMBER, littleEndian); 
     121        } 
     122        DataTools.writeInt(out, 8, littleEndian); // offset to first IFD 
    125123        lastOffset = 8; 
    126124        if (isBigTiff) { 
    127           DataTools.writeLong(dataOut, 16, littleEndian); 
     125          DataTools.writeLong(out, 16, littleEndian); 
    128126          lastOffset = 16; 
    129127        } 
  • trunk/components/common/src/loci/common/Location.java

    r4535 r4900  
    137137  } 
    138138 
     139  /** 
     140   * Gets an IRandomAccess object that can read from or write to the given file. 
     141   * @see IRandomAccess 
     142   */ 
     143  public static IRandomAccess getHandle(String id) throws IOException { 
     144    File f = new File(getMappedId(id)).getAbsoluteFile(); 
     145    if (getMappedFile(id) != null) return getMappedFile(id); 
     146 
     147    IRandomAccess handle = null; 
     148    if (id.startsWith("http://")) { 
     149      handle = new RAUrl(getMappedId(id), "r"); 
     150    } 
     151    else { 
     152      handle = new RAFile(f, "r"); 
     153    } 
     154    return handle; 
     155  } 
     156 
    139157  // -- File API methods -- 
    140158 
  • trunk/components/common/src/loci/common/RandomAccessStream.java

    r4678 r4900  
    104104   */ 
    105105  public RandomAccessStream(String file) throws IOException { 
    106     File f = new File(Location.getMappedId(file)); 
    107     f = f.getAbsoluteFile(); 
    108     if (Location.getMappedFile(file) != null) { 
    109       raf = Location.getMappedFile(file); 
    110       length = raf.length(); 
    111     } 
    112     else if (f.exists()) { 
    113       raf = new RAFile(f, "r"); 
    114  
     106    String path = Location.getMappedId(file); 
     107    File f = new File(path).getAbsoluteFile(); 
     108    raf = Location.getHandle(file); 
     109    length = raf.length(); 
     110 
     111    if (raf == null) { 
     112      throw new IOException("File not found: " + file); 
     113    } 
     114 
     115    if (f.exists()) { 
    115116      BufferedInputStream bis = new BufferedInputStream( 
    116         new FileInputStream(Location.getMappedId(file)), MAX_OVERHEAD); 
    117  
    118       String path = f.getPath().toLowerCase(); 
     117        new FileInputStream(path), MAX_OVERHEAD); 
    119118 
    120119      if (path.endsWith(".gz")) { 
     
    129128        } 
    130129 
    131         bis = new BufferedInputStream( 
    132           new FileInputStream(Location.getMappedId(file)), MAX_OVERHEAD); 
     130        bis = new BufferedInputStream(new FileInputStream(path), MAX_OVERHEAD); 
    133131        dis = new DataInputStream(new GZIPInputStream(bis)); 
    134132      } 
    135133      else if (path.endsWith(".zip")) { 
    136         ZipFile zf = new ZipFile(Location.getMappedId(file)); 
     134        ZipFile zf = new ZipFile(path); 
    137135 
    138136        // strip off .zip extension and directory prefix 
     
    177175        } 
    178176 
    179         bis = new BufferedInputStream( 
    180           new FileInputStream(Location.getMappedId(file)), MAX_OVERHEAD); 
     177        bis = new BufferedInputStream(new FileInputStream(path), MAX_OVERHEAD); 
    181178        bis.skip(2); 
    182179        dis = new DataInputStream(new CBZip2InputStream(bis)); 
     
    185182 
    186183      if (!compressed) { 
    187         length = raf.length(); 
    188184        buf = new byte[(int) (length < MAX_OVERHEAD ? length : MAX_OVERHEAD)]; 
    189185        raf.readFully(buf); 
     
    192188      } 
    193189    } 
    194     else if (file.startsWith("http")) { 
    195       raf = new RAUrl(Location.getMappedId(file), "r"); 
    196       length = raf.length(); 
    197     } 
    198     else throw new IOException("File not found : " + file); 
    199190    this.file = file; 
    200191    fp = 0; 
     
    647638  /** Re-open a file that has been closed */ 
    648639  private void reopen() throws IOException { 
    649     File f = new File(Location.getMappedId(file)); 
    650     f = f.getAbsoluteFile(); 
    651     if (Location.getMappedFile(file) != null) { 
    652       raf = Location.getMappedFile(file); 
    653       length = raf.length(); 
    654     } 
    655     else if (f.exists()) { 
    656       raf = new RAFile(f, "r"); 
    657  
     640    String path = Location.getMappedId(file); 
     641    File f = new File(path).getAbsoluteFile(); 
     642 
     643    raf = Location.getHandle(file); 
     644    length = raf.length(); 
     645 
     646    if (f.exists()) { 
    658647      BufferedInputStream bis = new BufferedInputStream( 
    659648        new FileInputStream(Location.getMappedId(file)), MAX_OVERHEAD); 
    660649 
    661       String path = f.getPath().toLowerCase(); 
     650      path = path.toLowerCase(); 
    662651 
    663652      if (dis != null) dis.close(); 
     
    682671 
    683672      if (!compressed) { 
    684         length = raf.length(); 
    685673        buf = new byte[(int) (length < MAX_OVERHEAD ? length : MAX_OVERHEAD)]; 
    686674        raf.readFully(buf); 
    687675        raf.seek(0); 
    688676      } 
    689     } 
    690     else if (file.startsWith("http")) { 
    691       raf = new RAUrl(Location.getMappedId(file), "r"); 
    692       length = raf.length(); 
    693677    } 
    694678    fileCache.put(this, Boolean.TRUE); 
Note: See TracChangeset for help on using the changeset viewer.