1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-21 12:35:10 +00:00

Merge pull request #664 from matthew16550/imageio-read-bytes

Extract ImageIO.read(byte[]) method
This commit is contained in:
arnaudroques 2021-09-12 12:35:01 +02:00 committed by GitHub
commit 5cb202295d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 32 deletions

View File

@ -41,7 +41,6 @@ import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -88,12 +87,9 @@ public class ClipboardLoop {
Log.info("No image generated");
} else {
Log.info("Image ok " + desc.getDescription());
final byte[] data = baos.toByteArray();
baos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(data);
final BufferedImage image = ImageIO.read(bais);
final BufferedImage image = ImageIO.read(baos.toByteArray());
setClipboardImage(image);
bais.close();
Log.info("Image copied in clipboard");
}
}

View File

@ -37,7 +37,6 @@ package net.sourceforge.plantuml;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
@ -187,10 +186,7 @@ public class EmbeddedDiagram implements CharSequence {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
system.exportDiagram(os, 0, new FileFormatOption(FileFormat.PNG));
os.close();
final ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
final BufferedImage im = ImageIO.read(is);
is.close();
return im;
return ImageIO.read(os.toByteArray());
}
public HorizontalAlignment getHorizontalAlignment() {

View File

@ -42,7 +42,6 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
@ -270,7 +269,7 @@ public abstract class UmlDiagram extends TitledDiagram implements Diagram, Annot
// exportDiagramTOxxBEREMOVED(baos, null, 0, new
// FileFormatOption(FileFormat.PNG, at));
baos.close();
final BufferedImage im = ImageIO.read(new ByteArrayInputStream(baos.toByteArray()));
final BufferedImage im = ImageIO.read(baos.toByteArray());
m.addImage(im);
}
m.finishAVI();

View File

@ -38,7 +38,6 @@ package net.sourceforge.plantuml.creole.atom;
import java.awt.Color;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import net.sourceforge.plantuml.Dimension2DDouble;
@ -157,7 +156,7 @@ public class AtomImg extends AbstractAtom implements Atom {
private static Atom buildRasterFromData(String source, final FontConfiguration fc, final byte[] data, double scale,
Url url) throws IOException {
final BufferedImage read = ImageIO.read(new ByteArrayInputStream(data));
final BufferedImage read = ImageIO.read(data);
if (read == null) {
return AtomTextUtils.createLegacy("(Cannot decode: " + source + ")", fc);
}

View File

@ -35,9 +35,7 @@
*/
package net.sourceforge.plantuml.eggs;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import net.sourceforge.plantuml.PlainStringsDiagram;
import net.sourceforge.plantuml.core.DiagramDescription;
@ -60,10 +58,7 @@ public class PSystemRIP extends PlainStringsDiagram {
strings.add(" <b>Requiescat In Pace");
strings.add(" ");
final InputStream is = new ByteArrayInputStream(imm);
image = ImageIO.read(is);
is.close();
image = ImageIO.read(imm);
imagePosition = GraphicPosition.BOTTOM;
}

View File

@ -40,7 +40,6 @@ import static net.sourceforge.plantuml.ugraphic.ImageBuilder.plainPngBuilder;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@ -119,7 +118,7 @@ public class ScientificEquationSafe {
}
try {
final byte[] bytes = plainPngBuilder(getRollback()).writeByteArray();
return new PixelImage(ImageIO.read(new ByteArrayInputStream(bytes)), AffineTransformType.TYPE_BILINEAR);
return new PixelImage(ImageIO.read(bytes), AffineTransformType.TYPE_BILINEAR);
} catch (IOException e1) {
return null;
}

View File

@ -37,6 +37,7 @@ package net.sourceforge.plantuml.security;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -76,6 +77,10 @@ public class ImageIO {
public static BufferedImage read(InputStream is) throws IOException {
return javax.imageio.ImageIO.read(is);
}
public static BufferedImage read(byte[] bytes) throws IOException {
return javax.imageio.ImageIO.read(new ByteArrayInputStream(bytes));
}
public static ImageInputStream createImageInputStream(java.io.File file) throws IOException {
return javax.imageio.ImageIO.createImageInputStream(file);

View File

@ -52,7 +52,6 @@ import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@ -336,7 +335,7 @@ class ImageWindow extends JFrame {
final TextBlockBackcolored error = GraphicStrings.createForError(Arrays.asList(msg), false);
try {
final byte[] bytes = plainPngBuilder(error).writeByteArray();
image = ImageIO.read(new ByteArrayInputStream(bytes));
image = ImageIO.read(bytes);
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -43,7 +43,6 @@ import java.awt.Shape;
import java.awt.font.TextLayout;
import java.awt.geom.PathIterator;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
@ -184,7 +183,7 @@ public class FontChecker {
}
};
final byte[] bytes = plainPngBuilder(drawable).writeByteArray();
return ImageIO.read(new ByteArrayInputStream(bytes));
return ImageIO.read(bytes);
}
// public BufferedImage getBufferedImageOld(char c) throws IOException {

View File

@ -43,7 +43,6 @@ import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@ -401,11 +400,7 @@ public class ImageBuilder {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeImageInternal(new FileFormatOption(FileFormat.PNG), baos, Animation.singleton(affineTransform));
baos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final Image im = ImageIO.read(bais);
bais.close();
return im;
return ImageIO.read(baos.toByteArray());
}
private UGraphic2 createUGraphic(FileFormatOption option, final Dimension2D dim, Animation animationArg, double dx,