@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); }
@Test public void testFitsUndefinedHdu4() throws Exception { Fits fits1 = makeAsciiTable(); fits1.read(); byte[] undefinedData = new byte[1000]; for (int index = 0; index < undefinedData.length; index++) { undefinedData[index] = (byte) index; } Data data = UndefinedHDU.encapsulate(undefinedData); Header header = new Header(); header.pointToData(data); fits1.addHDU(FitsFactory.hduFactory(header, data)); BufferedDataOutputStream os = new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU4.fits")); fits1.write(os); os.close(); Fits fits2 = new Fits("target/UndefindedHDU4.fits"); BasicHDU<?>[] hdus = fits2.read(); byte[] rereadUndefinedData = (byte[]) ((UndefinedData) hdus[hdus.length - 1].getData()).getData(); Assert.assertArrayEquals(undefinedData, rereadUndefinedData); ByteArrayOutputStream out = new ByteArrayOutputStream(); hdus[hdus.length - 1].info(new PrintStream(out)); String undefinedInfo = new String(out.toByteArray()); Assert.assertTrue(undefinedInfo.indexOf("Apparent size:1000") >= 0); }