Esempio n. 1
0
  @Test
  public void testreadWriteHdu() throws Exception {
    byte[] undefinedData = new byte[1000];
    for (int index = 0; index < undefinedData.length; index++) {
      undefinedData[index] = (byte) index;
    }
    UndefinedData data = UndefinedHDU.encapsulate(undefinedData);
    Header header = new Header();
    header.pointToData(data);
    UndefinedHDU hdu = new UndefinedHDU(header, data);

    hdu.getHeader().deleteKey("EXTEND");

    BufferedFile stream = new BufferedFile("target/rewriteHduTest.bin", "rw");
    hdu.write(stream);
    stream.close();

    stream = new BufferedFile("target/rewriteHduTest.bin", "rw");
    data = UndefinedHDU.encapsulate(new byte[0]);
    hdu = new UndefinedHDU(new Header(data), data);
    hdu.read(stream);
    hdu.addValue("TESTER", "WRITE", null);
    hdu.rewrite();
    hdu.reset();
    hdu.read(stream);
    hdu.getHeader().getStringValue("TESTER");

    byte[] rereadUndefinedData = (byte[]) hdu.getData().getData();
    Assert.assertArrayEquals(undefinedData, rereadUndefinedData);
  }
Esempio n. 2
0
  @Test
  public void testFitsUndefinedHdu5() throws Exception {
    Header head = new Header();
    head.setXtension("UNKNOWN");
    head.setBitpix(BasicHDU.BITPIX_BYTE);
    head.setNaxes(1);
    head.addValue("NAXIS1", 1000, null);
    head.addValue("PCOUNT", 0, null);
    head.addValue("GCOUNT", 2, null);
    UndefinedHDU hdu = (UndefinedHDU) FitsFactory.hduFactory(head);
    byte[] data = (byte[]) hdu.getData().getData();
    Assert.assertEquals(2000, data.length);
    Arrays.fill(data, (byte) 1);
    BufferedFile buf = new BufferedFile("target/testFitsUndefinedHdu5", "rw");
    hdu.write(buf);
    buf.close();
    Arrays.fill(data, (byte) 2);

    buf = new BufferedFile("target/testFitsUndefinedHdu5", "rw");
    hdu.read(buf);
    data = (byte[]) hdu.getData().getData();
    buf.close();
    Assert.assertEquals((byte) 1, data[0]);
  }
Esempio n. 3
0
 private void writeFile(Fits f, String name) throws Exception {
   BufferedFile bf = new BufferedFile(name, "rw");
   f.write(bf);
   bf.flush();
   bf.close();
 }