Ejemplo n.º 1
0
  /**
   * 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;
  }
Ejemplo n.º 2
0
 /**
  * Reads 4 bytes and concatenates them into a String. This pattern is used for ID's of various
  * kinds.
  */
 public String read4Chars(DataInputStream stream) throws IOException {
   StringBuffer sbuf = new StringBuffer(4);
   for (int i = 0; i < 4; i++) {
     int ch = readUnsignedByte(stream, this);
     if (ch != 0) {
       sbuf.append((char) ch); // omit nulls
     }
   }
   return sbuf.toString();
 }
Ejemplo n.º 3
0
  /**
   * 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();
  }