예제 #1
0
  /**
   * Read a file offset from the file PST Files have this tendency to store file offsets (pointers)
   * in 8 little endian bytes. Convert this to a long for seeking to.
   *
   * @param in handle for PST file
   * @param startOffset where to read the 8 bytes from
   * @return long representing the read location
   * @throws IOException
   */
  protected long extractLEFileOffset(long startOffset) throws IOException {
    long offset = 0;
    if (this.getPSTFileType() == PSTFile.PST_TYPE_ANSI) {
      in.seek(startOffset);
      byte[] temp = new byte[4];
      in.read(temp);
      offset |= temp[3] & 0xff;
      offset <<= 8;
      offset |= temp[2] & 0xff;
      offset <<= 8;
      offset |= temp[1] & 0xff;
      offset <<= 8;
      offset |= temp[0] & 0xff;
    } else {
      in.seek(startOffset);
      byte[] temp = new byte[8];
      in.read(temp);
      offset = temp[7] & 0xff;
      long tmpLongValue;
      for (int x = 6; x >= 0; x--) {
        offset = offset << 8;
        tmpLongValue = (long) temp[x] & 0xff;
        offset |= tmpLongValue;
      }
    }

    return offset;
  }
예제 #2
0
  /**
   * Copy the given byte range of the given input to the given output.
   *
   * @param input The input to copy the given range to the given output for.
   * @param output The output to copy the given range from the given input for.
   * @param start Start of the byte range.
   * @param length Length of the byte range.
   * @throws IOException If something fails at I/O level.
   */
  private static void copy(RandomAccessFile input, OutputStream output, long start, long length)
      throws IOException {
    byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
    int read;

    if (input.length() == length) {
      // Write full range.
      while ((read = input.read(buffer)) > 0) {
        output.write(buffer, 0, read);
      }
    } else {
      // Write partial range.
      input.seek(start);
      long toRead = length;

      while ((read = input.read(buffer)) > 0) {
        if ((toRead -= read) > 0) {
          output.write(buffer, 0, read);
        } else {
          output.write(buffer, 0, (int) toRead + read);
          break;
        }
      }
    }
  }
예제 #3
0
  private void loadDataXM(RandomAccessFile fp) throws IOException {
    byte[] b = new byte[20];

    // WHY THE HELL AM I DOING THIS
    name = Util.readStringNoNul(fp, b, 20);
    System.out.printf("name: \"%s\"\n", name);
    fp.read(); // skip 0x1A byte

    // THIS CAN'T BE HAPPENING
    fp.read(b, 0, 20); // skip tracker name

    // OH HELL NO
    int xmver = 0xFFFF & (int) Short.reverseBytes(fp.readShort());
    System.out.printf("XM version: %04X\n", xmver);

    // WHAT IS THIS CRAP
    InhibitedFileBlock ifb = new InhibitedFileBlock(fp, Integer.reverseBytes(fp.readInt()) - 4);

    // HELP ME PLEASE
    int ordnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int respos =
        0xFFFF & (int) Short.reverseBytes(ifb.readShort()); // can't be bothered right now --GM
    int chnnum =
        0xFFFF & (int) Short.reverseBytes(ifb.readShort()); // yeah sure, allow out of range values
    if (chnnum > 64)
      throw new RuntimeException(
          String.format("%d-channel modules not supported (max 64)", chnnum));
    int patnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int insnum = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmflags = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmspeed = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());
    int xmtempo = 0xFFFF & (int) Short.reverseBytes(ifb.readShort());

    // OH PLEASE, STOP IT
    if (ordnum > 255) ordnum = 255;
    if (xmtempo > 255) xmtempo = 255;
    if (xmspeed > 255) xmspeed = 255;
    this.bpm = xmtempo;
    this.spd = xmspeed;
    this.flags = FLAG_COMPATGXX | FLAG_OLDEFFECTS | FLAG_INSMODE | FLAG_STEREO | FLAG_VOL0MIX;

    if ((xmflags & 0x01) != 0) this.flags |= FLAG_LINEAR;

    // NONONONONONO
    System.out.printf("chn=%d ordnum=%d tempo=%d speed=%s\n", chnnum, ordnum, xmtempo, xmspeed);
    for (int i = 0; i < 256; i++) orderlist[i] = ifb.read();
    for (int i = ordnum; i < 256; i++) orderlist[i] = 255;

    ifb.done();

    // SAVE ME PLEEEEEAAASSSSEEEE
    for (int i = 0; i < patnum; i++)
      map_pat.put((Integer) i, new SessionPattern(this, fp, SessionPattern.FORMAT_XM, chnnum));
    for (int i = 0; i < insnum; i++)
      map_ins.put((Integer) (i + 1), new SessionInstrument(fp, SessionInstrument.FORMAT_XM, this));
  }
예제 #4
0
  /*
   * gets an (uncompressed) stream representing the chunk data returns null if
   * the chunk is not found or an error occurs
   */
  public synchronized DataInputStream getChunkDataInputStream(int x, int z) {
    if (outOfBounds(x, z)) {
      debugln("READ", x, z, "out of bounds");
      return null;
    }

    try {
      int offset = getOffset(x, z);
      if (offset == 0) {
        // debugln("READ", x, z, "miss");
        return null;
      }

      int sectorNumber = offset >> 8;
      int numSectors = offset & 0xFF;

      if (sectorNumber + numSectors > sectorFree.size()) {
        debugln("READ", x, z, "invalid sector");
        return null;
      }

      file.seek(sectorNumber * SECTOR_BYTES);
      int length = file.readInt();

      if (length > SECTOR_BYTES * numSectors) {
        debugln("READ", x, z, "invalid length: " + length + " > 4096 * " + numSectors);
        return null;
      }

      byte version = file.readByte();
      if (version == VERSION_GZIP) {
        byte[] data = new byte[length - 1];
        file.read(data);
        DataInputStream ret =
            new DataInputStream(
                new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(data))));
        // debug("READ", x, z, " = found");
        return ret;
      } else if (version == VERSION_DEFLATE) {
        byte[] data = new byte[length - 1];
        file.read(data);
        DataInputStream ret =
            new DataInputStream(
                new BufferedInputStream(new InflaterInputStream(new ByteArrayInputStream(data))));
        // debug("READ", x, z, " = found");
        return ret;
      }

      debugln("READ", x, z, "unknown version " + version);
      return null;
    } catch (IOException e) {
      debugln("READ", x, z, "exception");
      return null;
    }
  }
예제 #5
0
 public int luaCB_read(Lua l, LuaPlugin plugin) {
   l.pushNil();
   l.pushNil();
   try {
     long offset = (long) l.checkNumber(2);
     int length = (int) l.checkNumber(3);
     if (length <= 0) {
       l.pushNil();
       l.pushString("Length is not positive");
       return 2;
     }
     byte[] tmp = new byte[length];
     object.seek(offset);
     length = object.read(tmp);
     if (length < 0) {
       l.pushNil();
       l.pushNil();
       return 2;
     }
     StringBuffer buf = new StringBuffer(length);
     for (byte x : tmp) buf.appendCodePoint((int) x & 0xFF);
     l.push(buf.toString());
   } catch (IOException e) {
     l.pushNil();
     l.pushString("IOException: " + e.getMessage());
     return 2;
   }
   return 1;
 }
예제 #6
0
 /**
  * reads the content of an existing file using the current domain
  *
  * @param domain The namespace used to identify the application domain (1st level directory) to
  *     use
  * @param path The path relative to the domain for the file
  * @param block The sequential block number for the data to be read starting with 1
  * @param len The length of the block in bytes
  * @return The contents of the file
  */
 public byte[] readFromFile(String path, int block, int len) {
   byte[] buffer = null;
   try {
     if (_isLocal) {
       File tmpFile = new File(_rootFile.getCanonicalPath() + File.separatorChar + path);
       if (tmpFile.isFile()) {
         RandomAccessFile in = new RandomAccessFile(tmpFile, "r");
         in.seek((block - 1) * len);
         int result = -1;
         buffer = new byte[len];
         if (in.getFilePointer() < in.length()) {
           result = in.read(buffer);
           ByteArrayOutputStream out = new ByteArrayOutputStream(result);
           out.write(buffer, 0, result);
           in.close();
           return out.toByteArray();
         } else {
           in.close();
         }
       }
     } else {
       buffer = _remote.readFromFile(_domain, path, block, len);
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   return buffer;
 }
예제 #7
0
  /**
   * Loads a query from the mgf file.
   *
   * @param file The file to read the query from.
   * @param indexElement The index element pointing to that specific ms2 query.
   * @return
   * @oaram index The query's 1-based index in the MGF file. This index is stored in the returned
   *     Ms2Query object.
   */
  private static Ms2Query loadIndexedQueryFromFile(File file, IndexElement indexElement, int index)
      throws JMzReaderException {
    RandomAccessFile accFile = null;
    try {
      accFile = new RandomAccessFile(file, "r");

      // read the indexed element
      byte[] byteBuffer = new byte[indexElement.getSize()];

      // read the file from there
      accFile.seek(indexElement.getStart());
      accFile.read(byteBuffer);
      String ms2Buffer = new String(byteBuffer);
      // create the query
      Ms2Query query = new Ms2Query(ms2Buffer, index);

      return query;
    } catch (FileNotFoundException e) {
      throw new JMzReaderException("MGF file could not be found.", e);
    } catch (IOException e) {
      throw new JMzReaderException("Failed to read from MGF file", e);
    } finally {
      if (accFile != null) {
        try {
          accFile.close();
        } catch (IOException e) {
          // ignore
        }
      }
    }
  }
 /**
  * Fills the buffer with more data, taking into account shuffling and other tricks for dealing
  * with marks. Assumes that it is being called by a synchronized method. This method also assumes
  * that all data has already been read in, hence pos > count.
  */
 private void fill() throws IOException {
   if (markpos < 0) {
     pos = 0; /* no mark: throw away the buffer */
     bufpos += count;
   } else if (pos >= buf.length) /* no room left in buffer */
     if (markpos > 0) {
       /* can throw away early part of the buffer */
       int sz = pos - markpos;
       System.arraycopy(buf, markpos, buf, 0, sz);
       pos = sz;
       bufpos += markpos;
       markpos = 0;
     } else if (buf.length >= marklimit) {
       markpos = -1; /* buffer got too big, invalidate mark */
       pos = 0; /* drop buffer contents */
       bufpos += count;
     } else {
       /* grow buffer */
       int nsz = pos * 2;
       if (nsz > marklimit) nsz = marklimit;
       byte nbuf[] = new byte[nsz];
       System.arraycopy(buf, 0, nbuf, 0, pos);
       buf = nbuf;
     }
   count = pos;
   // limit to datalen
   int len = buf.length - pos;
   if (bufpos - start + pos + len > datalen) len = (int) (datalen - (bufpos - start + pos));
   synchronized (in) {
     in.seek(bufpos + pos);
     int n = in.read(buf, pos, len);
     if (n > 0) count = n + pos;
   }
 }
예제 #9
0
 /**
  * reads the content of an existing file using the current domain
  *
  * @param domain The namespace used to identify the application domain (1st level directory) to
  *     use
  * @param path The path relative to the domain for the file
  * @param offset the offset from the beginning of the file.
  * @param len The length of the block in bytes
  * @return The contents of the file
  */
 public byte[] readByteFromFile(String path, long offset, int len)
     throws EOFException, FileAccessException {
   try {
     if (_isLocal) {
       File tmpFile = new File(_rootFile.getCanonicalPath() + File.separatorChar + path);
       if (tmpFile.isFile()) {
         RandomAccessFile raf = new RandomAccessFile(tmpFile, "r");
         byte[] buffer = new byte[len];
         raf.seek(offset);
         int totalByteRead = 0;
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         int result = 0;
         while (totalByteRead < len && raf.getFilePointer() < raf.length()) {
           result = raf.read(buffer, 0, (len - totalByteRead));
           if (result != -1) {
             out.write(buffer, 0, result);
             totalByteRead += result;
           } else if (totalByteRead == 0) throw new EOFException("End of file reached!");
           else break;
         }
         raf.close();
         out.flush();
         out.close();
         return out.toByteArray();
       } else throw new FileAccessException("Path is not a file");
     } else return _remote.readByteFromFile(_domain, path, offset, len);
   } catch (EOFException eofe) {
     throw eofe;
   } catch (FileAccessException fae) {
     throw fae;
   } catch (Exception e) {
     throw new FileAccessException(e);
   }
 }
예제 #10
0
파일: IFD.java 프로젝트: KOST-CECO/SIP-Val
  /**
   * Reads an array of strings from the TIFF file.
   *
   * @param count Number of strings to read
   * @param value Offset from which to read
   */
  protected String[] readASCIIArray(long count, long value) throws IOException {
    _raf.seek(value);

    int nstrs = 0;
    List list = new LinkedList();
    byte[] buf = new byte[(int) count];
    _raf.read(buf);
    StringBuffer strbuf = new StringBuffer();
    for (int i = 0; i < count; i++) {
      int b = buf[i];
      if (b == 0) {
        list.add(strbuf.toString());
        strbuf.setLength(0);
      } else {
        strbuf.append((char) b);
      }
    }
    /* We can't use ArrayList.toArray because that returns an
    Object[], not a String[] ... sigh. */
    String[] strs = new String[nstrs];
    ListIterator iter = list.listIterator();
    for (int i = 0; i < nstrs; i++) {
      strs[i] = (String) iter.next();
    }
    return strs;
  }
예제 #11
0
  public PSTFile(File fileName) throws FileNotFoundException, PSTException, IOException {
    // attempt to open the file.
    in = new RandomAccessFile(fileName, "r");

    // get the first 4 bytes, should be !BDN
    try {
      byte[] temp = new byte[4];
      in.read(temp);
      String strValue = new String(temp);
      if (!strValue.equals("!BDN")) {
        throw new PSTException("Invalid file header: " + strValue + ", expected: !BDN");
      }

      // make sure we are using a supported version of a PST...
      byte[] fileTypeBytes = new byte[2];
      in.seek(10);
      in.read(fileTypeBytes);
      // ANSI file types can be 14 or 15:
      if (fileTypeBytes[0] == PSTFile.PST_TYPE_ANSI_2) {
        fileTypeBytes[0] = PSTFile.PST_TYPE_ANSI;
      }
      if (fileTypeBytes[0] != PSTFile.PST_TYPE_ANSI
          && fileTypeBytes[0] != PSTFile.PST_TYPE_UNICODE) {
        throw new PSTException("Unrecognised PST File version: " + fileTypeBytes[0]);
      }
      this.pstFileType = fileTypeBytes[0];

      // make sure encryption is turned off at this stage...
      if (this.getPSTFileType() == PST_TYPE_ANSI) {
        in.seek(461);
      } else {
        in.seek(513);
      }
      encryptionType = in.readByte();
      if (encryptionType == 0x02) {
        throw new PSTException(
            "Only unencrypted and compressable PST files are supported at this time");
      }

      // build out name to id map.
      processNameToIdMap(in);

    } catch (IOException err) {
      throw new PSTException("Unable to read PST Sig", err);
    }
  }
예제 #12
0
  public String getLine(int lineNo) throws Exception {
    if (lineNo <= 0 || lineNo > mNumLines) {
      return null;
    }

    String line = null;
    Jedis jedis = pool_.getResource();
    try {
      String lineNoStr = Integer.toString(lineNo);
      line = jedis.hget(lineNoStr, LINE_KEY);
      if (line == null) {
        RecordId lineId = getRecordId(lineNo);

        byte[] buffer = new byte[BLOCK_SIZE];
        synchronized (mDataFile) {
          mDataFile.seek(lineId.pageNo() * BLOCK_SIZE);
          mDataFile.read(buffer);
        }
        ByteBuffer bb = ByteBuffer.wrap(buffer);

        int numRecords = bb.getInt(BLOCK_SIZE - INT_SIZE);
        int indexPos = BLOCK_SIZE - 3 * INT_SIZE;
        int curLineNo = lineNo - lineId.slotNo() + 1;
        String[] recordKeys = {PAGE_NO_KEY, SLOT_NO_KEY};
        for (int i = 1; i < numRecords; i++, curLineNo++) {
          int offset = bb.getInt(indexPos);
          int len = bb.getInt(indexPos + INT_SIZE);

          ByteBuffer linebb = ByteBuffer.wrap(buffer, offset, len);
          byte[] lineBuf = new byte[linebb.remaining()];
          linebb.get(lineBuf);
          String lineStr = new String(lineBuf);

          if (i == lineId.slotNo()) {
            line = lineStr;
          }

          // Store in cache
          lineNoStr = Integer.toString(curLineNo);
          jedis.hdel(lineNoStr, recordKeys);
          jedis.hset(lineNoStr, LINE_KEY, lineStr);
          indexPos -= 2 * INT_SIZE;
        }
      }

      if (line == null) {
        throw new Exception("LineServer: Could not find line on page");
      }
    } catch (IOException ioe) {
      System.err.println("LineServer: IOException on line retrieval");
      throw ioe;
    } finally {
      pool_.returnResource(jedis);
    }

    return line;
  }
예제 #13
0
 /**
  * Fully reads a block from a section of the file into the given byte[] array at the given
  * position.
  */
 public void readFully(final long position, byte[] buf, int off, int len) throws IOException {
   synchronized (data) {
     data.seek(position);
     int to_read = len;
     while (to_read > 0) {
       int read = data.read(buf, off, to_read);
       to_read -= read;
       off += read;
     }
   }
 }
예제 #14
0
 /**
  * reads the content of a group of existing files in a zipped block
  *
  * @param domain The namespace used to identify the application domain (1st level directory) to
  *     use
  * @param paths The paths relative to the domain for the files to be read
  * @param offset The offset in the file to start reading from
  * @param len The length of the block in bytes in zipped form
  * @return The contents of the file in zipped form together with the description of the files
  */
 public MultiFileBlock readFromStreamZipped(String[] paths, long offset, int len) {
   MultiFileBlock block = null;
   try {
     if (_isLocal) {
       int startFileIndex =
           Util.getStartFileIndex(
               _rootFile.getCanonicalPath() + File.separatorChar, paths, offset);
       long startFileOffset =
           Util.getStartFileOffset(
               _rootFile.getCanonicalPath() + File.separatorChar, paths, offset);
       int i = startFileIndex;
       long j = startFileOffset;
       // int bufSize=0;
       int totalBufSize = 0;
       int readResult = 0;
       ByteArrayOutputStream bOut = new ByteArrayOutputStream(len);
       GZIPOutputStream zOut = new GZIPOutputStream(bOut, len);
       block = new MultiFileBlock();
       while (totalBufSize < len && i < paths.length) {
         File tmpFile = new File(_rootFile.getCanonicalPath() + File.separatorChar + paths[i]);
         if (tmpFile.isFile() && tmpFile.exists()) {
           RandomAccessFile in = new RandomAccessFile(tmpFile, "r");
           byte[] tmpBuf = new byte[len - totalBufSize];
           in.seek(j);
           while (totalBufSize < len && in.getFilePointer() < in.length()) {
             readResult = in.read(tmpBuf);
             if (readResult != -1) {
               zOut.write(tmpBuf, 0, readResult);
               // bufSize = bOut.size();
               totalBufSize += readResult;
             } else {
               break;
             }
           }
           BlockFileDescriptor des = new BlockFileDescriptor(_domain, paths[i], in.length());
           block.addBlockFileDescriptor(des);
           in.close();
           i++;
           j = 0;
         } else {
           return null;
         }
       }
       zOut.close();
       block.setBlockData(bOut.toByteArray());
     } else {
       block = _remote.readFromStreamZipped(_domain, paths, offset, len);
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   return block;
 }
예제 #15
0
  public static void readBinary() {
    RandomAccessFile fi = null;
    DataInputStream di = null;
    try {
      fi = new RandomAccessFile("binary.bi", "r");
      fi.seek(3);
      byte[] demo = new byte[3];
      fi.read(demo, 0, 3);
      System.out.println(new String(demo));
      fi.seek(6);
      fi.read(demo, 0, 3);
      System.out.println(new String(demo));
      //            di = new DataInputStream(new FileInputStream("binary.bi"));
      //            di.skipBytes(3);
      //            di.read(demo, 0, 6);
      //            System.out.println(new String(demo));

    } catch (Exception E) {
      E.printStackTrace();
    }
  }
예제 #16
0
  int getBytes(byte[] ary, int start) {
    int x = 0;
    try {
      rf.seek(start);

      x = rf.read(ary, 0, ary.length);
      System.out.println("start " + start + " length " + x + " first " + ary[0]);
    } catch (IOException ex) {
      return 0;
    }
    return x;
  }
예제 #17
0
  /* returns the byte data*/
  public byte[] getPdfBuffer() {

    byte[] bytes = new byte[length];
    try {
      buf.seek(0);
      buf.read(bytes);
    } catch (IOException e) {
      e.printStackTrace();
    }

    return bytes;
  }
예제 #18
0
 /**
  * Assuming the file has an id3v2 tag, returns true if the tag can be overwritten. We cannot
  * overwrite id3v2 tags not supported
  *
  * @param raf
  * @return
  * @throws IOException
  */
 private boolean canOverwrite(RandomAccessFile raf) throws IOException {
   raf.seek(3);
   // Version du tag ID3v2.xx.xx
   String versionHigh = raf.read() + "";
   if (!(versionHigh.equals("4") || versionHigh.equals("3") || versionHigh.equals("2")))
     return false; // only version 2.3.xx
   // raf.read();
   // int flag = raf.read() & 128;
   // if (flag == 128)
   // return false; //unsynchronised tags not supported
   return true;
 }
예제 #19
0
 static FileSendingFormat readFromFile(RandomAccessFile rf, byte[] ary, long startPos) {
   int bytes = 0;
   synchronized (rf) {
     try {
       rf.seek(startPos);
       bytes = rf.read(ary, 0, ary.length);
       System.out.println(">>>" + rf.getFilePointer() + " ff " + (startPos + bytes));
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   return new FileSendingFormat(ary, startPos, bytes);
 }
예제 #20
0
  private void doTheDamnThing(RandomAccessFile fp) throws IOException {
    byte[] b = new byte[26];

    // Load IMPM header
    fp.read(b, 0, 4);
    if (b[0] == 'I' && b[1] == 'M' && b[2] == 'P' && b[3] == 'M') {
      loadDataIT(fp);
      return;
    }

    // Attempt to load XM
    fp.seek(0);
    if (Util.readStringNoNul(fp, b, 17).equals("Extended Module: ")) {
      fp.seek(17 + 20);
      if (fp.read() == 0x1A) {
        fp.seek(17);
        loadDataXM(fp);
        return;
      }
    }

    // Attempt to load ST3 module
    fp.seek(0x1C);
    if (fp.readUnsignedShort() == 0x1A10) {
      fp.seek(0);
      loadDataS3M(fp);
      return;
    }

    fp.seek(0);

    // Assume this is a .mod file
    if (true) {
      loadDataMOD(fp);
      return;
    }

    throw new RuntimeException("module format not supported");
  }
예제 #21
0
 public String namify(Integer value) throws IOException {
   File f = new File(graphName + "_names.dat");
   if (!f.exists()) {
     System.out.println("didn't find name file: " + f.getPath());
     return value + "";
   }
   int i = value * 16;
   RandomAccessFile raf = new RandomAccessFile(f.getAbsolutePath(), "r");
   raf.seek(i);
   byte[] tmp = new byte[16];
   raf.read(tmp);
   raf.close();
   return new String(tmp) + "(" + value + ")";
 }
예제 #22
0
파일: GIDE.java 프로젝트: rexut/jkcemu
 private void execReadSectorsTask() {
   File file = this.ioFile;
   long pos = this.ioFilePos;
   if (this.debugLevel > 3) {
     System.out.printf("GIDE io task: read track, pos=%d", pos);
   }
   if ((file != null) && (pos >= 0)) {
     if (file.exists()) {
       RandomAccessFile raf = null;
       try {
         raf = new RandomAccessFile(file, "r");
         raf.seek(pos);
         this.ioByteCnt = (int) raf.read(this.ioBuf, 0, this.ioByteCnt);
         if (this.debugLevel > 3) {
           System.out.printf("GIDE io task: read sector: %d read\n", this.ioByteCnt);
         }
       } catch (IOException ex) {
         if (this.debugLevel > 3) {
           System.out.println("GIDE io task: read sector: error");
         }
         if (!this.readErrShown) {
           this.readErrShown = true;
           EmuUtil.fireShowError(
               this.owner,
               "Die Festplattenabbilddatei kann nicht gelesen"
                   + " werden.\n"
                   + "Gegen\u00FCber dem emulierten System"
                   + " wird jedoch kein Fehler signalisiert.",
               ex);
         }
       } finally {
         EmuUtil.doClose(raf);
       }
     } else {
       EmuUtil.fireShowError(
           this.owner,
           "Die Festplattenabbilddatei existiert nicht und"
               + " kann deshalb auch nicht gelesen werden.\n"
               + "Gegen\u00FCber dem emulierten System"
               + " wird jedoch kein Fehler signalisiert.\n"
               + "Mit dem ersten Schreibzugriff auf das"
               + " emulierte Laufwerk wird die Abbilddatei"
               + " angelegt.",
           null);
     }
     this.ioBufPos = 0;
     this.statusReg |= STATUS_DATA_REQUEST;
     fireInterrupt();
   }
 }
예제 #23
0
파일: IFD.java 프로젝트: KOST-CECO/SIP-Val
  /**
   * Reads a string value from the TIFF file.
   *
   * @param count Length of string
   * @param value Offset of string
   */
  protected String readASCII(long count, long value) throws IOException {
    _raf.seek(value);

    byte[] buffer = new byte[(int) count];
    _raf.read(buffer);

    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < count; i++) {
      if (buffer[i] == 0) {
        break;
      }
      sb.append((char) buffer[i]);
    }
    return sb.toString();
  }
예제 #24
0
 /** constructs a frequency table from a file */
 public static int[] constructTable(RandomAccessFile file) {
   int[] ret = new int[TABLESIZE];
   try {
     file.seek(0L);
     long l = file.length();
     for (long i = 0; i < l; i++) {
       int c = file.read();
       ret[c]++;
     }
     return ret;
   } catch (Exception ex) {
     ExHandler.handle(ex);
     return null;
   }
 }
  public static Map<String, Integer> queryTF(
      String word,
      Map<String, TokenCatalogBean> tokenCatBean,
      Map<String, DocBean> docCatBean,
      Utility u,
      String folder)
      throws IOException {

    Map<String, Integer> results = new HashMap<>();
    long startOffset = 0;
    long endOffset = 0;
    word = word.toLowerCase().trim();

    if (tokenCatBean.containsKey(word)) {
      // System.out.println("tokenCatBeanContains the word "+word);
      startOffset = tokenCatBean.get(word).getStartOffset();
      endOffset = tokenCatBean.get(word).getEndOffset();
      // System.out.println("StartOffset:: "+startOffset);
      // System.out.println("EndOffset:: "+endOffset);

      RandomAccessFile raf =
          new RandomAccessFile("C:\\Users\\Nitin\\Assign2\\" + folder + "\\TermsHash84.txt", "r");
      raf.seek(startOffset);
      byte[] termLine = new byte[(int) (endOffset - startOffset)];
      raf.read(termLine);
      String term = new String(termLine);
      // System.out.println("Term Fetched:::: "+term);

      String[] termOutput = term.split(" ");
      // System.out.println("last splitTerm"+
      // termOutput[termOutput.length-1]);

      for (int i = 1; i < termOutput.length - 1; i++) {

        String s = termOutput[i];
        // System.out.println("String output:: "+s);
        String[] docDetail = s.split(":");
        int docId = Integer.parseInt(docDetail[0]);
        int endIndex = docDetail[1].indexOf("-");
        int tF = Integer.parseInt(docDetail[1].substring(0, endIndex));
        results.put(u.getDocKey(docId), tF);
      }

      raf.close();
    }

    return results;
  }
예제 #26
0
 // see DbFile.java for javadocs
 public Page readPage(PageId pid) {
   // some code goes here
   try {
     RandomAccessFile rAf = new RandomAccessFile(f, "r");
     int offset = pid.pageNumber() * BufferPool.PAGE_SIZE;
     byte[] b = new byte[BufferPool.PAGE_SIZE];
     rAf.seek(offset);
     rAf.read(b, 0, BufferPool.PAGE_SIZE);
     HeapPageId hpid = (HeapPageId) pid;
     rAf.close();
     return new HeapPage(hpid, b);
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
예제 #27
0
파일: IFD.java 프로젝트: KOST-CECO/SIP-Val
  /** Reads an array of SRATIONAL values and returns it as an array of Rational. */
  protected Rational[] readSignedRationalArray(long count, long value) throws IOException {
    _raf.seek(value);

    byte[] buffer = new byte[(int) calcValueSize(SRATIONAL, count)];
    _raf.read(buffer);
    DataInputStream stream = new DataInputStream(new ByteArrayInputStream(buffer));

    Rational[] rarray = new Rational[(int) count];
    for (int i = 0; i < count; i++) {
      long numer = ModuleBase.readSignedInt(stream, _bigEndian, null);
      long denom = ModuleBase.readSignedInt(stream, _bigEndian, null);
      rarray[i] = new Rational(numer, denom);
    }

    return rarray;
  }
      public int testRead(final String fileName) throws Exception {
        RandomAccessFile file = new RandomAccessFile(fileName, "r");
        final byte[] buffer = new byte[PAGE_SIZE];
        int checkSum = 0;
        int bytesRead;

        while (-1 != (bytesRead = file.read(buffer))) {
          for (int i = 0; i < bytesRead; i++) {
            checkSum += buffer[i];
          }
        }

        file.close();

        return checkSum;
      }
예제 #29
0
  /**
   * Get the next rtp packet recorded in the rtpdump file.
   *
   * @param loopFile if true, when the end of the rtpdump file is reached, this
   *     <tt>RtpdumpFileReader</tt> will go back at the beginning of the file and get the first
   *     packet.
   * @return a <tt>RawPacket</tt> containing all the information and data of the next rtp packet
   *     recorded in the rtpdump file
   * @throws IOException if <tt>loopFile</tt> was false and the end of the file is reached.
   */
  public RawPacket getNextPacket(boolean loopFile) throws IOException {
    if (loopFile && (stream.getFilePointer() >= stream.length())) {
      resetFile();
    }

    byte[] rtpdumpPacket;
    int sizeInBytes;

    stream.readShort(); // read away an useless short (2 bytes)
    sizeInBytes = stream.readUnsignedShort();
    rtpdumpPacket = new byte[sizeInBytes];
    stream.readInt(); // read away the rtpdump timestamp

    stream.read(rtpdumpPacket);

    return new RawPacket(rtpdumpPacket, 0, rtpdumpPacket.length);
  }
예제 #30
0
  // Invariant: should be at beginning of record
  public long getNextRecordIndex() {
    long offset = file_pos + buffer_pos;

    boolean on_seq_header = true;
    boolean on_seq = false;
    boolean on_qual_header = false;
    boolean on_qual = false;

    int num_seq_lines = 0;
    int num_qual_lines = 0;

    try {
      while (true) {
        if (buffer_size == 0 || buffer_pos >= buffer_size) {
          file_pos = filein.getFilePointer();
          buffer_size = filein.read(buffer);
          buffer_pos = 0;
        }
        if (buffer_size < 1) return -1;

        if (buffer[buffer_pos] == '+' && on_seq) {
          on_qual_header = true;
        }

        if (buffer[buffer_pos] == '\n') {

          if (on_qual) {
            num_qual_lines++;
            if (num_seq_lines == num_qual_lines) {
              buffer_pos++;
              return offset;
            }
          } else if (on_qual_header) {
            on_qual = true;
          } else if (on_seq) {
            num_seq_lines++;
          } else if (on_seq_header) {
            on_seq = true;
          }
        }
        buffer_pos++;
      }
    } catch (Exception e) {
      return -1;
    }
  }