Package net.ivoa.fits

Examples of net.ivoa.fits.FitsException


      }

      os.write(new byte[FitsUtil.padding(getTrueSize())]);

    } catch (IOException e) {
      throw new FitsException("Unable to write table:" + e);
    }

  }
View Full Code Here


  public Object getData() throws FitsException {

    if (table == null) {

      if (currInput == null) {
        throw new FitsException("Cannot find input for deferred read");
      }

      table = createTable();

      long currentOffset = FitsUtil.findOffset(currInput);
View Full Code Here

    for (int i = 0; i < nFields; i += 1) {
      offsets[i] = hdr.getIntValue("TBCOL" + (i + 1)) - 1;
      String s = hdr.getStringValue("TFORM" + (i + 1));
      if (offsets[i] < 0) {
        throw new FitsException("Invalid Specification for column:"
            + (i + 1));
      }
      s = s.trim();
      char c = s.charAt(0);
      s = s.substring(1);
View Full Code Here

    if (str instanceof RandomAccess) {

      try {
        str.skipBytes(nRows * rowLen);
      } catch (IOException e) {
        throw new FitsException("Error skipping data: " + e);
      }

    } else {
      try {
        getBuffer(rowLen * nRows, 0);
      } catch (IOException e) {
        throw new FitsException("Error reading ASCII table:" + e);
      }
    }

    try {
      str.skipBytes(FitsUtil.padding(nRows * rowLen));
    } catch (IOException e) {
      throw new FitsException("Error skipping padding:" + e);
    }
  }
View Full Code Here

        long newOffset = FitsUtil.findOffset(currInput);
        try {
          getBuffer(nRows * rowLen, fileOffset);

        } catch (IOException e) {
          throw new FitsException(
              "Error in deferred read -- file closed prematurely?:"
                  + e);
        }
        FitsUtil.reposition(currInput, newOffset);
      }
View Full Code Here

      } else if (array[col] instanceof double[]) {
        ((double[]) array[col])[row] = bp.getDouble(length);
      } else if (array[col] instanceof long[]) {
        ((long[]) array[col])[row] = bp.getLong(length);
      } else {
        throw new FitsException(
            "Invalid type for ASCII table conversion:" + array[col]);
      }
    } catch (FormatException e) {
      throw new FitsException("Error parsing data at row,col:" + row
          + "," + col + "  " + e);
    }
    return true;
  }
View Full Code Here

    Object[] res = new Object[nFields];

    try {
      getBuffer(rowLen, fileOffset + row * rowLen);
    } catch (IOException e) {
      throw new FitsException("Unable to read row");
    }

    for (int i = 0; i < nFields; i += 1) {
      res[i] = ArrayFuncs.newInstance(types[i], 1);
      if (!extractElement(offsets[i], lengths[i], res, i, 0, nulls[i])) {
View Full Code Here

    Object[] res = new Object[1];
    try {
      getBuffer(lengths[col], fileOffset + row * rowLen + offsets[col]);
    } catch (IOException e) {
      buffer = null;
      throw new FitsException("Unable to read element");
    }
    res[0] = ArrayFuncs.newInstance(types[col], 1);

    if (extractElement(0, lengths[col], res, 0, 0, nulls[col])) {
      buffer = null;
View Full Code Here

    // since nothing we've done has invalidated it.

    if (buffer == null) {

      if (data == null) {
        throw new FitsException(
            "Attempt to write undefined ASCII Table");
      }

      buffer = new byte[nRows * rowLen];
      bp = new ByteParser(buffer);
      for (int i = 0; i < buffer.length; i += 1) {
        buffer[i] = (byte) ' ';
      }

      ByteFormatter bf = new ByteFormatter();
      bf.setTruncationThrow(false);
      bf.setTruncateOnOverflow(true);

      for (int i = 0; i < nRows; i += 1) {

        for (int j = 0; j < nFields; j += 1) {
          int offset = i * rowLen + offsets[j];
          int len = lengths[j];

          try {
            if (isNull != null && isNull[i * nFields + j]) {
              if (nulls[j] == null) {
                throw new FitsException(
                    "No null value set when needed");
              }
              bf.format(nulls[j], buffer, offset, len);
            } else {
              if (types[j] == String.class) {
                String[] s = (String[]) data[j];
                bf.format(s[i], buffer, offset, len);
              } else if (types[j] == int.class) {
                int[] ia = (int[]) data[j];
                bf.format(ia[i], buffer, offset, len);
              } else if (types[j] == float.class) {
                float[] fa = (float[]) data[j];
                bf.format(fa[i], buffer, offset, len);
              } else if (types[j] == double.class) {
                double[] da = (double[]) data[j];
                bf.format(da[i], buffer, offset, len);
              } else if (types[j] == long.class) {
                long[] la = (long[]) data[j];
                bf.format(la[i], buffer, offset, len);
              }
            }
          } catch (TruncationException e) {
            System.err.println("Ignoring truncation error:" + i
                + "," + j);
          }
        }
      }
    }

    // Now write the buffer.
    try {
      str.write(buffer);
      byte[] padding = new byte[FitsUtil.padding(buffer.length)];
      for (int i = 0; i < padding.length; i += 1) {
        padding[i] = (byte) ' ';
      }
      if (buffer.length > 0) {
        str.write(padding);
      }
      str.flush();
    } catch (IOException e) {
      throw new FitsException("Error writing ASCII Table data");
    }
  }
View Full Code Here

      getData();
    }
    if (col < 0 || col >= nFields
        || newData.getClass() != data[col].getClass()
        || Array.getLength(newData) != Array.getLength(data[col])) {
      throw new FitsException("Invalid column/column mismatch:" + col);
    }
    data[col] = newData;

    // Invalidate the buffer.
    buffer = null;
View Full Code Here

TOP

Related Classes of net.ivoa.fits.FitsException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.