@Test public void testFlushOnAdapterDoesNotMoveFlushedPositionInBacking() throws IOException { MemoryCacheImageOutputStream backing = new MemoryCacheImageOutputStream(new ByteArrayOutputStream()); IIOOutputStreamAdapter adapter = new IIOOutputStreamAdapter(backing); // Sanity check assertEquals(0, backing.getFlushedPosition()); // Write & flush adapter.write(0xCA); adapter.write(new byte[8]); adapter.write(0xFE); adapter.flush(); // Assertions assertEquals(10, backing.length()); assertEquals(10, backing.getStreamPosition()); assertEquals(0, backing.getFlushedPosition()); // Just make sure we can safely seek back to start and read data back backing.seek(0); assertEquals(0, backing.getStreamPosition()); // If this can be read, I think the contract of flush is also fulfilled (kind of) assertEquals(0xCA, backing.read()); assertEquals(8, backing.skipBytes(8)); assertEquals(0xFE, backing.read()); } }
private void compress() throws IOException { if (cache != null) return; if (ex != null) throw ex; try { BufferedImage bi = Compressor.this.readFrame(frameIndex); Compressor.this.extractEmbeddedOverlays(frameIndex, bi); if (bitsStored < bitsAllocated) Compressor.this.nullifyUnusedBits(bitsStored, bi); cache = new FlushlessMemoryCacheImageOutputStream(cacheout, imageDescriptor); compressor.setOutput(patchJPEGLS != null ? new PatchJPEGLSImageOutputStream(cache, patchJPEGLS) : cache); long start = System.currentTimeMillis(); compressor.write(null, new IIOImage(bi, null, null), compressParam); long end = System.currentTimeMillis(); streamLength = (int) cache.getStreamPosition(); if (LOG.isDebugEnabled()) LOG.debug("Compressed frame #{} {}:1 in {} ms", new Object[] {frameIndex + 1, (float) sizeOf(bi) / streamLength, end - start }); Compressor.this.verify(cache, frameIndex); } catch (IOException ex) { cache = null; Compressor.this.ex = ex; throw ex; } }
public void testInit() throws IOException, IllegalCeosFormatException { final BaseImageFileDescriptorRecord record = createImageFileDescriptor(_reader, _prefix.length()); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + BaseRecordTest.RECORD_LENGTH, _ios.getStreamPosition()); assertRecord(record); }
public void testInit_SimpleConstructor() throws IOException, IllegalCeosFormatException { _reader.seek(_prefix.length()); final BaseImageFileDescriptorRecord record = createImageFileDescriptorRecord(_reader); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + BaseRecordTest.RECORD_LENGTH, _ios.getStreamPosition()); assertRecord(record); }
private void assertRecord(final Ancillary2Record record) throws IOException { BaseRecordTest.assertRecord(record); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + RECORD_LENGTH, _ios.getStreamPosition()); assertEquals("OB4 ", record.getSensorOperationMode()); assertEquals(1234, record.getLowerLimitOfStrengthAfterCorrection()); assertEquals(3241, record.getUpperLimitOfStrengthAfterCorrection()); assertEquals("abcdef", record.getSensorGains()); assertSpecificRecordData(record); }
private void assertRecord(final TextRecord record) throws IOException { BaseRecordTest.assertRecord(record); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + 360, _ios.getStreamPosition()); assertEquals("A ", record.getCodeCharacter()); assertEquals("O1B2R_UB", record.getProductID()); assertEquals("PROCESS:JAPAN-JAXA-EOC-ALOS-DPS 20060410075225 ", record.getFacility()); assertEquals("ALPSMB003062950", record.getSceneID()); assertEquals("BSQ ", record.getImageFormat()); } }
private void assertRecord(final ImageRecord record) throws IOException { BaseRecordTest.assertRecord(record); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + BaseRecordTest.RECORD_LENGTH, _ios.getStreamPosition()); assertEquals(1234, record.getPrefixDataLineNumber()); assertEquals(2345, record.getImageNumber()); assertEquals(3456, record.getScanStartTimeMillisAtDay()); assertEquals(4567, record.getScanStartTimeMicros()); assertEquals(5678, record.getNumLeftDummyPixels()); assertEquals(6789, record.getNumRightDummyPixels()); } }
@Test public void testFlushOnAdapterDoesNotMoveFlushedPositionInBacking() throws IOException { MemoryCacheImageOutputStream backing = new MemoryCacheImageOutputStream(new ByteArrayOutputStream()); IIOOutputStreamAdapter adapter = new IIOOutputStreamAdapter(backing); // Sanity check assertEquals(0, backing.getFlushedPosition()); // Write & flush adapter.write(0xCA); adapter.write(new byte[8]); adapter.write(0xFE); adapter.flush(); // Assertions assertEquals(10, backing.length()); assertEquals(10, backing.getStreamPosition()); assertEquals(0, backing.getFlushedPosition()); // Just make sure we can safely seek back to start and read data back backing.seek(0); assertEquals(0, backing.getStreamPosition()); // If this can be read, I think the contract of flush is also fulfilled (kind of) assertEquals(0xCA, backing.read()); assertEquals(8, backing.skipBytes(8)); assertEquals(0xFE, backing.read()); } }
public void testReadInArrayWithBlanks() throws IOException, IllegalCeosFormatException { final String prefix = "vspdfoperilfdkposnsern"; _ios.writeBytes(prefix); _ios.writeBytes("123 45 67"); // 9 ints with length 1 _ios.writeBytes("suffix"); final CeosFileReader ceosReader = new CeosFileReader(_ios); ceosReader.seek(prefix.length()); final int[] ints = ceosReader.readInArray(9, 1); assertNotNull(ints); assertEquals(9, ints.length); assertEquals(1, ints[0]); assertEquals(2, ints[1]); assertEquals(3, ints[2]); assertEquals(0, ints[3]); assertEquals(4, ints[4]); assertEquals(5, ints[5]); assertEquals(0, ints[6]); assertEquals(6, ints[7]); assertEquals(7, ints[8]); assertEquals(prefix.length() + 9 * 1, _ios.getStreamPosition()); }
public void testReadInArray() throws IOException, IllegalCeosFormatException { final String prefix = "vspdfoperilfdkposnsern"; _ios.writeBytes(prefix); _ios.writeBytes("123"); // 0 _ios.writeBytes(" 45"); // 1 _ios.writeBytes(" 6"); // 2 _ios.writeBytes(" 46"); // 3 _ios.writeBytes(" 7 "); // 4 _ios.writeBytes("234"); // 5 _ios.writeBytes("suffix"); final CeosFileReader ceosReader = new CeosFileReader(_ios); ceosReader.seek(prefix.length()); final int[] ints = ceosReader.readInArray(6, 3); assertNotNull(ints); assertEquals(6, ints.length); assertEquals(123, ints[0]); assertEquals(45, ints[1]); assertEquals(6, ints[2]); assertEquals(46, ints[3]); assertEquals(7, ints[4]); assertEquals(234, ints[5]); assertEquals(prefix.length() + 6 * 3, _ios.getStreamPosition()); }
private void assertRecord(final VolumeDescriptorRecord record) throws IOException { BaseRecordTest.assertRecord(record); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + 360, _ios.getStreamPosition()); assertEquals("AB", record.getAsciiCodeCharacter()); assertEquals("abcdefghijkl", record.getSpecificationNumber()); assertEquals("CD", record.getSpecificationRevisionNumber()); assertEquals("EF", record.getRecordFormatRevisionNumer()); assertEquals("bcdefghijklm", record.getSoftwareVersionNumber()); assertEquals("cdefghijklmnopqr", record.getLogicalVolumeID()); assertEquals("defghijklmnopqrs", record.getVolumeSetID()); assertEquals(12, record.getVolumeNumberOfThisVolumeDescritorRecord()); assertEquals(2345, record.getNumberOfFirstFileFollowingTheVolumeDirectoryFile()); assertEquals(3456, record.getLogicalVolumeNumberInVolumeSet()); assertEquals("efghijkl", record.getLogicalVolumePreparationDate()); assertEquals("fghijklm", record.getLogicalVolumePreparationTime()); assertEquals("ghijklmnopqr", record.getLogicalVolumePreparationCountry()); assertEquals("hijklmno", record.getLogicalVolumePreparingAgent()); assertEquals("ijklmnopqrst", record.getLogicalVolumePreparingFacility()); assertEquals(4567, record.getNumberOfFilepointerRecords()); assertEquals(5678, record.getNumberOfRecords()); } }
BaseRecordTest.assertRecord(record); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + RECORD_LENGTH, _ios.getStreamPosition());
private void assertRecord(final Ancillary3Record record) throws IOException { BaseRecordTest.assertRecord(record); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + 4680, _ios.getStreamPosition());
BaseRecordTest.assertRecord(record); assertEquals(_prefix.length(), record.getStartPos()); assertEquals(_prefix.length() + RECORD_LENGTH, _ios.getStreamPosition());