use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class EndWriteSequenceTest method main.
public static void main(String[] args) throws IOException {
ImageWriter w = ImageIO.getImageWritersByFormatName("GIF").next();
boolean gotCorrectException = false;
/**
* check statement: "Throws: IllegalStateException -
* if the output has not been set ...."
*/
try {
// to be shure that output is null
w.reset();
w.endWriteSequence();
} catch (IllegalStateException e) {
gotCorrectException = true;
} catch (Throwable e) {
throw new RuntimeException("Test failed.", e);
}
if (!gotCorrectException) {
throw new RuntimeException("Test failed.");
}
/**
* set up output stream
*/
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
w.setOutput(ios);
/**
* check statement: "Throws: IllegalStateException -
* if .... prepareWriteSequence has not been called.
*/
gotCorrectException = false;
try {
w.endWriteSequence();
} catch (IllegalStateException e) {
gotCorrectException = true;
} catch (Throwable e) {
throw new RuntimeException("Test failed.", e);
}
if (!gotCorrectException) {
throw new RuntimeException("Test failed.");
}
System.out.println("Test passed.");
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class OddPaletteTest method doTest.
private static void doTest(BufferedImage src) {
ImageWriter w = ImageIO.getImageWritersByFormatName("GIF").next();
if (w == null) {
throw new RuntimeException("No writer available!");
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
w.setOutput(ios);
w.write(src);
} catch (IOException e) {
throw new RuntimeException("Test failed.", e);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Test failed.", e);
}
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class CreateMemoryCacheOutputStream method main.
public static void main(String[] args) {
ImageIO.setUseCache(false);
OutputStream os = new ByteArrayOutputStream();
ImageOutputStream stream = null;
try {
stream = ImageIO.createImageOutputStream(os);
} catch (Exception e) {
throw new RuntimeException("Got exception " + e);
}
if (stream == null) {
throw new RuntimeException("Got null stream!");
}
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class DeleteOnExitTest method main.
public static void main(String[] args) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(new byte[100]);
ByteArrayOutputStream os = new ByteArrayOutputStream();
String tmp = System.getProperty("java.io.tmpdir", ".");
System.out.println("tmp: " + tmp);
// count number of files before test
ImageIO.setUseCache(true);
ImageIO.setCacheDirectory(new File(tmp));
File tmpDir = ImageIO.getCacheDirectory();
System.out.println("tmpDir is " + tmpDir);
int fnum_before = tmpDir.list().length;
System.out.println("Files before test: " + fnum_before);
ImageInputStream iis = ImageIO.createImageInputStream(is);
System.out.println("iis = " + iis);
ImageInputStream iis2 = ImageIO.createImageInputStream(is);
ImageOutputStream ios = ImageIO.createImageOutputStream(os);
System.out.println("ios = " + ios);
ImageOutputStream ios2 = ImageIO.createImageOutputStream(os);
iis2.close();
ios2.close();
int fnum_after = tmpDir.list().length;
System.out.println("Files after test: " + fnum_after);
if (fnum_before == fnum_after) {
throw new RuntimeException("Test failed: cache was not used.");
}
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class MemoryCacheImageOutputStreamTest method main.
public static void main(String[] args) throws IOException {
try {
MemoryCacheImageOutputStream stream = new MemoryCacheImageOutputStream(new ByteArrayOutputStream());
// or write anything, for that matter
stream.write(0);
stream.flush();
} catch (Exception e) {
throw new RuntimeException("Error flushing stream: " + e);
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
byte[] b = new byte[30 * 256];
byte byteVal = (byte) 0;
for (int i = 0; i < b.length; i++) {
b[i] = byteVal++;
}
// Write 261,120 bytes
for (int i = 0; i < 34; i++) {
ios.write(b);
}
// Scatter 256 values at positions 1000, 2000, ...
// Using both write(int) and write(byte[])
byte[] buf = new byte[1];
for (int i = 0; i < 256; i += 2) {
ios.seek(1000 * i);
ios.write(i);
ios.seek(1000 * (i + 1));
buf[0] = (byte) (i + 1);
ios.write(buf);
}
// Re-read scattered values
for (int i = 0; i < 256; i++) {
ios.seek(1000 * i);
int val = ios.read();
if (val != i) {
System.out.println("Got bad value (1) at pos = " + (1000 * i));
}
}
// Discard two buffers and re-read scattered values
ios.flushBefore(2 * 8192);
for (int i = 0; i < 256; i++) {
long pos = 1000 * i;
if (pos >= 2 * 8192) {
ios.seek(pos);
int val = ios.read();
if (val != i) {
System.out.println("Got bad value (2) at pos = " + (1000 * i));
}
}
}
ios.close();
byte[] data = os.toByteArray();
for (int i = 0; i < data.length; i++) {
byte val = data[i];
if ((i < 256000) && (i % 1000) == 0) {
if (val != (byte) (i / 1000)) {
System.out.println("Got bad value (3) at pos = " + i);
}
} else {
byte gval = (byte) ((i % (30 * 256)) % 256);
if (val != gval) {
System.out.println("Got bad value (4) at pos = " + i + "(got " + (val & 0xff) + " wanted " + (gval & 0xff) + ")");
}
}
}
}
Aggregations