mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-17 02:35:09 +00:00
Merge pull request #663 from matthew16550/auto-close
Refactor some code to use AutoCloseable / try-with-resources
This commit is contained in:
commit
5e20da92f2
@ -60,8 +60,7 @@ public class AFileZipEntry implements AFile {
|
|||||||
public InputStream openFile() {
|
public InputStream openFile() {
|
||||||
final InputStream tmp = zipFile.openFile();
|
final InputStream tmp = zipFile.openFile();
|
||||||
if (tmp != null)
|
if (tmp != null)
|
||||||
try {
|
try (final ZipInputStream zis = new ZipInputStream(tmp)) {
|
||||||
final ZipInputStream zis = new ZipInputStream(tmp);
|
|
||||||
ZipEntry ze = zis.getNextEntry();
|
ZipEntry ze = zis.getNextEntry();
|
||||||
|
|
||||||
while (ze != null) {
|
while (ze != null) {
|
||||||
@ -73,7 +72,6 @@ public class AFileZipEntry implements AFile {
|
|||||||
ze = zis.getNextEntry();
|
ze = zis.getNextEntry();
|
||||||
}
|
}
|
||||||
zis.closeEntry();
|
zis.closeEntry();
|
||||||
zis.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -64,19 +64,15 @@ public final class BlockUmlBuilder implements DefinitionsContainer {
|
|||||||
|
|
||||||
public BlockUmlBuilder(List<String> config, String charset, Defines defines, Reader readerInit, SFile newCurrentDir,
|
public BlockUmlBuilder(List<String> config, String charset, Defines defines, Reader readerInit, SFile newCurrentDir,
|
||||||
String desc) throws IOException {
|
String desc) throws IOException {
|
||||||
ReadLineNumbered includer = null;
|
|
||||||
this.defines = defines;
|
this.defines = defines;
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
try {
|
this.reader = new UncommentReadLine(ReadLineReader.create(readerInit, desc));
|
||||||
this.reader = new UncommentReadLine(ReadLineReader.create(readerInit, desc));
|
this.importedFiles = ImportedFiles.createImportedFiles(new AParentFolderRegular(newCurrentDir));
|
||||||
this.importedFiles = ImportedFiles.createImportedFiles(new AParentFolderRegular(newCurrentDir));
|
|
||||||
includer = new Preprocessor(config, reader);
|
try (ReadLineNumbered includer = new Preprocessor(config, reader)) {
|
||||||
init(includer);
|
init(includer);
|
||||||
} finally {
|
} finally {
|
||||||
if (includer != null) {
|
|
||||||
includer.close();
|
|
||||||
// usedFiles = includer.getFilesUsedTOBEREMOVED();
|
|
||||||
}
|
|
||||||
readerInit.close();
|
readerInit.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,9 +139,9 @@ public class FileUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public void copyToFile(byte[] src, SFile dest) throws IOException {
|
static public void copyToFile(byte[] src, SFile dest) throws IOException {
|
||||||
final OutputStream fos = dest.createBufferedOutputStream();
|
try (OutputStream fos = dest.createBufferedOutputStream()) {
|
||||||
fos.write(src);
|
fos.write(src);
|
||||||
fos.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String readSvg(SFile svgFile) throws IOException {
|
static public String readSvg(SFile svgFile) throws IOException {
|
||||||
|
@ -210,9 +210,7 @@ public class OptionFlags {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// final PSystemError systemError = (PSystemError) system;
|
// final PSystemError systemError = (PSystemError) system;
|
||||||
PrintStream ps = null;
|
try (PrintStream ps = SecurityUtils.createPrintStream(logData.createFileOutputStream(true))) {
|
||||||
try {
|
|
||||||
ps = SecurityUtils.createPrintStream(logData.createFileOutputStream(true));
|
|
||||||
ps.println("Start of " + file.getName());
|
ps.println("Start of " + file.getName());
|
||||||
ps.println(warnOrError);
|
ps.println(warnOrError);
|
||||||
ps.println("End of " + file.getName());
|
ps.println("End of " + file.getName());
|
||||||
@ -220,10 +218,6 @@ public class OptionFlags {
|
|||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.error("Cannot open " + logData);
|
Log.error("Cannot open " + logData);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
if (ps != null) {
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,17 +225,11 @@ public class OptionFlags {
|
|||||||
public final void setLogData(SFile logData) {
|
public final void setLogData(SFile logData) {
|
||||||
this.logData = logData;
|
this.logData = logData;
|
||||||
logData.delete();
|
logData.delete();
|
||||||
PrintStream ps = null;
|
try (PrintStream ps = SecurityUtils.createPrintStream(logData.createFileOutputStream())) {
|
||||||
try {
|
|
||||||
ps = SecurityUtils.createPrintStream(logData.createFileOutputStream());
|
|
||||||
ps.println();
|
ps.println();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.error("Cannot open " + logData);
|
Log.error("Cannot open " + logData);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
if (ps != null) {
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,17 +297,10 @@ public class Run {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream stream = null;
|
|
||||||
final BufferedImage im;
|
final BufferedImage im;
|
||||||
try {
|
try (InputStream stream = source.openStream()) {
|
||||||
stream = source.openStream();
|
|
||||||
im = ImageIO.read(stream);
|
im = ImageIO.read(stream);
|
||||||
} finally {
|
|
||||||
if (stream != null) {
|
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name = getSpriteName(fileName);
|
final String name = getSpriteName(fileName);
|
||||||
final String s = compressed ? SpriteUtils.encodeCompressed(im, name, level)
|
final String s = compressed ? SpriteUtils.encodeCompressed(im, name, level)
|
||||||
: SpriteUtils.encode(im, name, level);
|
: SpriteUtils.encode(im, name, level);
|
||||||
@ -545,24 +538,24 @@ public class Run {
|
|||||||
.withPreprocFormat();
|
.withPreprocFormat();
|
||||||
final SFile file = suggested.getFile(0);
|
final SFile file = suggested.getFile(0);
|
||||||
Log.info("Export preprocessing source to " + file.getPrintablePath());
|
Log.info("Export preprocessing source to " + file.getPrintablePath());
|
||||||
final PrintWriter pw = charset == null ? file.createPrintWriter() : file.createPrintWriter(charset);
|
try (final PrintWriter pw = charset == null ? file.createPrintWriter() : file.createPrintWriter(charset)) {
|
||||||
int level = 0;
|
int level = 0;
|
||||||
for (CharSequence cs : blockUml.getDefinition(true)) {
|
for (CharSequence cs : blockUml.getDefinition(true)) {
|
||||||
String s = cs.toString();
|
String s = cs.toString();
|
||||||
if (cypher != null) {
|
if (cypher != null) {
|
||||||
if (s.contains("skinparam") && s.contains("{")) {
|
if (s.contains("skinparam") && s.contains("{")) {
|
||||||
level++;
|
level++;
|
||||||
}
|
}
|
||||||
if (level == 0 && s.contains("skinparam") == false) {
|
if (level == 0 && s.contains("skinparam") == false) {
|
||||||
s = cypher.cypher(s);
|
s = cypher.cypher(s);
|
||||||
}
|
}
|
||||||
if (level > 0 && s.contains("}")) {
|
if (level > 0 && s.contains("}")) {
|
||||||
level--;
|
level--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
pw.println(s);
|
||||||
}
|
}
|
||||||
pw.println(s);
|
|
||||||
}
|
}
|
||||||
pw.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,11 +143,8 @@ public class SignatureUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getSignatureSha512(SFile f) throws IOException {
|
public static String getSignatureSha512(SFile f) throws IOException {
|
||||||
final InputStream is = f.openFile();
|
try (InputStream is = f.openFile()) {
|
||||||
try {
|
|
||||||
return getSignatureSha512(is);
|
return getSignatureSha512(is);
|
||||||
} finally {
|
|
||||||
is.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,9 +180,8 @@ public class SignatureUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized String getSignature(SFile f) throws IOException {
|
public static synchronized String getSignature(SFile f) throws IOException {
|
||||||
try {
|
try (final InputStream is = f.openFile()) {
|
||||||
final MessageDigest msgDigest = MessageDigest.getInstance("MD5");
|
final MessageDigest msgDigest = MessageDigest.getInstance("MD5");
|
||||||
final InputStream is = f.openFile();
|
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
@ -193,7 +189,6 @@ public class SignatureUtils {
|
|||||||
while ((read = is.read()) != -1) {
|
while ((read = is.read()) != -1) {
|
||||||
msgDigest.update((byte) read);
|
msgDigest.update((byte) read);
|
||||||
}
|
}
|
||||||
is.close();
|
|
||||||
final byte[] digest = msgDigest.digest();
|
final byte[] digest = msgDigest.digest();
|
||||||
return toString(digest);
|
return toString(digest);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
@ -108,17 +108,10 @@ public abstract class SourceFileReaderAbstract implements ISourceFileReader {
|
|||||||
|
|
||||||
private List<GeneratedImage> getCrashedImage(BlockUml blockUml, Throwable t, SFile outputFile) throws IOException {
|
private List<GeneratedImage> getCrashedImage(BlockUml blockUml, Throwable t, SFile outputFile) throws IOException {
|
||||||
final GeneratedImage image = new GeneratedImageImpl(outputFile, "Crash Error", blockUml, FileImageData.CRASH);
|
final GeneratedImage image = new GeneratedImageImpl(outputFile, "Crash Error", blockUml, FileImageData.CRASH);
|
||||||
OutputStream os = null;
|
try (OutputStream os = outputFile.createBufferedOutputStream()) {
|
||||||
try {
|
|
||||||
os = outputFile.createBufferedOutputStream();
|
|
||||||
UmlDiagram.exportDiagramError(os, t, fileFormatOption, 42, null, blockUml.getFlashData(),
|
UmlDiagram.exportDiagramError(os, t, fileFormatOption, 42, null, blockUml.getFlashData(),
|
||||||
UmlDiagram.getFailureText2(t, blockUml.getFlashData()));
|
UmlDiagram.getFailureText2(t, blockUml.getFlashData()));
|
||||||
} finally {
|
|
||||||
if (os != null) {
|
|
||||||
os.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Collections.singletonList(image);
|
return Collections.singletonList(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,9 +121,9 @@ public abstract class SourceFileReaderAbstract implements ISourceFileReader {
|
|||||||
if (warnOrError != null) {
|
if (warnOrError != null) {
|
||||||
final String name = f.getName().substring(0, f.getName().length() - 4) + ".err";
|
final String name = f.getName().substring(0, f.getName().length() - 4) + ".err";
|
||||||
final SFile errorFile = f.getParentFile().file(name);
|
final SFile errorFile = f.getParentFile().file(name);
|
||||||
final PrintStream ps = SecurityUtils.createPrintStream(errorFile.createFileOutputStream());
|
try (PrintStream ps = SecurityUtils.createPrintStream(errorFile.createFileOutputStream())) {
|
||||||
ps.print(warnOrError);
|
ps.print(warnOrError);
|
||||||
ps.close();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,14 +110,9 @@ public class SourceStringReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DiagramDescription outputImage(SFile f) throws IOException {
|
public DiagramDescription outputImage(SFile f) throws IOException {
|
||||||
final OutputStream os = f.createBufferedOutputStream();
|
try (OutputStream os = f.createBufferedOutputStream()) {
|
||||||
DiagramDescription result = null;
|
return outputImage(os, 0);
|
||||||
try {
|
|
||||||
result = outputImage(os, 0);
|
|
||||||
} finally {
|
|
||||||
os.close();
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -282,9 +282,10 @@ public abstract class UmlDiagram extends TitledDiagram implements Diagram, Annot
|
|||||||
private ImageData exportDiagramInternalPdf(OutputStream os, int index) throws IOException {
|
private ImageData exportDiagramInternalPdf(OutputStream os, int index) throws IOException {
|
||||||
final File svg = FileUtils.createTempFileLegacy("pdf", ".svf");
|
final File svg = FileUtils.createTempFileLegacy("pdf", ".svf");
|
||||||
final File pdfFile = FileUtils.createTempFileLegacy("pdf", ".pdf");
|
final File pdfFile = FileUtils.createTempFileLegacy("pdf", ".pdf");
|
||||||
final OutputStream fos = new BufferedOutputStream(new FileOutputStream(svg));
|
final ImageData result;
|
||||||
final ImageData result = exportDiagram(fos, index, new FileFormatOption(FileFormat.SVG));
|
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(svg))) {
|
||||||
fos.close();
|
result = exportDiagram(fos, index, new FileFormatOption(FileFormat.SVG));
|
||||||
|
}
|
||||||
PdfConverter.convert(svg, pdfFile);
|
PdfConverter.convert(svg, pdfFile);
|
||||||
FileUtils.copyToStream(pdfFile, os);
|
FileUtils.copyToStream(pdfFile, os);
|
||||||
return result;
|
return result;
|
||||||
@ -297,18 +298,11 @@ public abstract class UmlDiagram extends TitledDiagram implements Diagram, Annot
|
|||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
final String name = changeName(suggestedFile.getFile(index).getAbsolutePath());
|
final String name = changeName(suggestedFile.getFile(index).getAbsolutePath());
|
||||||
final SFile cmapFile = new SFile(name);
|
final SFile cmapFile = new SFile(name);
|
||||||
PrintWriter pw = null;
|
try (PrintWriter pw = cmapFile.createPrintWriter()) {
|
||||||
try {
|
|
||||||
if (PSystemUtils.canFileBeWritten(cmapFile) == false) {
|
if (PSystemUtils.canFileBeWritten(cmapFile) == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pw = cmapFile.createPrintWriter();
|
|
||||||
pw.print(cmapdata.getCMapData(cmapFile.getName().substring(0, cmapFile.getName().length() - 6)));
|
pw.print(cmapdata.getCMapData(cmapFile.getName().substring(0, cmapFile.getName().length() - 6)));
|
||||||
pw.close();
|
|
||||||
} finally {
|
|
||||||
if (pw != null) {
|
|
||||||
pw.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,24 +112,24 @@ public class CheckZipTask extends Task {
|
|||||||
private void loadZipFile(SFile file) throws IOException {
|
private void loadZipFile(SFile file) throws IOException {
|
||||||
|
|
||||||
this.entries.clear();
|
this.entries.clear();
|
||||||
final PrintWriter pw = SecurityUtils.createPrintWriter("tmp.txt");
|
|
||||||
final InputStream tmp = file.openFile();
|
final InputStream tmp = file.openFile();
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
final ZipInputStream zis = new ZipInputStream(tmp);
|
try (
|
||||||
ZipEntry ze = zis.getNextEntry();
|
final PrintWriter pw = SecurityUtils.createPrintWriter("tmp.txt");
|
||||||
|
final ZipInputStream zis = new ZipInputStream(tmp);
|
||||||
while (ze != null) {
|
) {
|
||||||
final String fileName = ze.getName();
|
ZipEntry ze = zis.getNextEntry();
|
||||||
this.entries.add(fileName);
|
while (ze != null) {
|
||||||
if (fileName.endsWith("/") == false) {
|
final String fileName = ze.getName();
|
||||||
pw.println("<file name=\"" + fileName + "\" />");
|
this.entries.add(fileName);
|
||||||
|
if (fileName.endsWith("/") == false) {
|
||||||
|
pw.println("<file name=\"" + fileName + "\" />");
|
||||||
|
}
|
||||||
|
ze = zis.getNextEntry();
|
||||||
}
|
}
|
||||||
ze = zis.getNextEntry();
|
|
||||||
}
|
}
|
||||||
pw.close();
|
|
||||||
zis.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void myLog(String s) {
|
private synchronized void myLog(String s) {
|
||||||
|
@ -49,12 +49,11 @@ public class CompressionBrotli implements Compression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ByteArray decompress(byte[] in) throws NoPlantumlCompressionException {
|
public ByteArray decompress(byte[] in) throws NoPlantumlCompressionException {
|
||||||
try {
|
try (
|
||||||
final BrotliInputStream brotli = new BrotliInputStream(new ByteArrayInputStream(in));
|
final BrotliInputStream brotli = new BrotliInputStream(new ByteArrayInputStream(in));
|
||||||
final ByteArrayOutputStream result = new ByteArrayOutputStream();
|
final ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||||
|
) {
|
||||||
FileUtils.copyToStream(brotli, result);
|
FileUtils.copyToStream(brotli, result);
|
||||||
brotli.close();
|
|
||||||
result.close();
|
|
||||||
return ByteArray.from(result.toByteArray());
|
return ByteArray.from(result.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -85,12 +85,10 @@ public class GroupPrinter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void print(SFile f, IGroup rootGroup) {
|
public static void print(SFile f, IGroup rootGroup) {
|
||||||
try {
|
try (PrintWriter pw = f.createPrintWriter()) {
|
||||||
final PrintWriter pw = f.createPrintWriter();
|
|
||||||
pw.println("<html>");
|
pw.println("<html>");
|
||||||
new GroupPrinter(pw).printGroup(rootGroup);
|
new GroupPrinter(pw).printGroup(rootGroup);
|
||||||
pw.println("</html>");
|
pw.println("</html>");
|
||||||
pw.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -85,30 +85,28 @@ public class OpenIcon {
|
|||||||
|
|
||||||
private OpenIcon(InputStream is, String id) throws IOException {
|
private OpenIcon(InputStream is, String id) throws IOException {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
|
||||||
String s = null;
|
String s = null;
|
||||||
while ((s = br.readLine()) != null) {
|
while ((s = br.readLine()) != null) {
|
||||||
rawData.add(s);
|
rawData.add(s);
|
||||||
if (s.contains("<path")) {
|
if (s.contains("<path")) {
|
||||||
final int x1 = s.indexOf('"');
|
final int x1 = s.indexOf('"');
|
||||||
final int x2 = s.indexOf('"', x1 + 1);
|
final int x2 = s.indexOf('"', x1 + 1);
|
||||||
svgPath = new SvgPath(s.substring(x1 + 1, x2));
|
svgPath = new SvgPath(s.substring(x1 + 1, x2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
br.close();
|
|
||||||
is.close();
|
|
||||||
if (rawData.size() != 3 && rawData.size() != 4) {
|
if (rawData.size() != 3 && rawData.size() != 4) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveCopy(SFile fnew) throws IOException {
|
void saveCopy(SFile fnew) throws IOException {
|
||||||
final PrintWriter pw = fnew.createPrintWriter();
|
try(PrintWriter pw = fnew.createPrintWriter()) {
|
||||||
pw.println(rawData.get(0));
|
pw.println(rawData.get(0));
|
||||||
pw.println(svgPath.toSvg());
|
pw.println(svgPath.toSvg());
|
||||||
pw.println(rawData.get(rawData.size() - 1));
|
pw.println(rawData.get(rawData.size() - 1));
|
||||||
pw.close();
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dimension2D getDimension(double factor) {
|
private Dimension2D getDimension(double factor) {
|
||||||
|
@ -66,14 +66,14 @@ public class PSystemListOpenIconic extends PlainDiagram {
|
|||||||
lines.add("<i>Credit to");
|
lines.add("<i>Credit to");
|
||||||
lines.add("https://useiconic.com/open");
|
lines.add("https://useiconic.com/open");
|
||||||
lines.add(" ");
|
lines.add(" ");
|
||||||
final BufferedReader br = new BufferedReader(new InputStreamReader(getRessourceAllTxt()));
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(getRessourceAllTxt()))) {
|
||||||
String s = null;
|
String s = null;
|
||||||
while ((s = br.readLine()) != null) {
|
while ((s = br.readLine()) != null) {
|
||||||
// lines.add("<¥> " + s);
|
// lines.add("<¥> " + s);
|
||||||
// System.err.println("s=" + s);
|
// System.err.println("s=" + s);
|
||||||
lines.add("<&" + s + "> " + s);
|
lines.add("<&" + s + "> " + s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
br.close();
|
|
||||||
final List<TextBlock> cols = PSystemDonors.getCols(lines, 7, 0);
|
final List<TextBlock> cols = PSystemDonors.getCols(lines, 7, 0);
|
||||||
return new TextBlockHorizontal(cols, VerticalAlignment.TOP);
|
return new TextBlockHorizontal(cols, VerticalAlignment.TOP);
|
||||||
}
|
}
|
||||||
|
@ -248,16 +248,10 @@ public class PicoWebServerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String httpRaw(String request) throws Exception {
|
private static String httpRaw(String request) throws Exception {
|
||||||
Socket socket = null;
|
try (Socket socket = socketConnection()) {
|
||||||
try {
|
|
||||||
socket = socketConnection();
|
|
||||||
socket.getOutputStream().write(request.getBytes(UTF_8));
|
socket.getOutputStream().write(request.getBytes(UTF_8));
|
||||||
socket.shutdownOutput();
|
socket.shutdownOutput();
|
||||||
return readStreamAsString(socket.getInputStream()).replaceAll("\r\n", "\n");
|
return readStreamAsString(socket.getInputStream()).replaceAll("\r\n", "\n");
|
||||||
} finally {
|
|
||||||
if (socket != null) {
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,14 +56,8 @@ public class PngIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void write(RenderedImage image, SFile file, String metadata, int dpi) throws IOException {
|
public static void write(RenderedImage image, SFile file, String metadata, int dpi) throws IOException {
|
||||||
OutputStream os = null;
|
try (OutputStream os = file.createBufferedOutputStream()) {
|
||||||
try {
|
|
||||||
os = file.createBufferedOutputStream();
|
|
||||||
write(image, os, metadata, dpi);
|
write(image, os, metadata, dpi);
|
||||||
} finally {
|
|
||||||
if (os != null) {
|
|
||||||
os.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Log.debug("File is " + file);
|
Log.debug("File is " + file);
|
||||||
Log.debug("File size " + file.length());
|
Log.debug("File size " + file.length());
|
||||||
|
@ -222,11 +222,11 @@ public class GraphvizSolverB {
|
|||||||
|
|
||||||
private void exportPng(final String dotString, SFile f) throws IOException {
|
private void exportPng(final String dotString, SFile f) throws IOException {
|
||||||
final Graphviz graphviz = GraphvizUtils.create(null, dotString, "png");
|
final Graphviz graphviz = GraphvizUtils.create(null, dotString, "png");
|
||||||
final OutputStream os = f.createBufferedOutputStream();
|
try (OutputStream os = f.createBufferedOutputStream()) {
|
||||||
final ProcessState state = graphviz.createFile3(os);
|
final ProcessState state = graphviz.createFile3(os);
|
||||||
os.close();
|
if (state.differs(ProcessState.TERMINATED_OK())) {
|
||||||
if (state.differs(ProcessState.TERMINATED_OK())) {
|
throw new IllegalStateException("Timeout3 " + state);
|
||||||
throw new IllegalStateException("Timeout3 " + state);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,27 +166,15 @@ public class StatsUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void htmlOutput(Stats stats) throws FileNotFoundException {
|
static void htmlOutput(Stats stats) throws FileNotFoundException {
|
||||||
PrintWriter pw = null;
|
try (PrintWriter pw = SecurityUtils.createPrintWriter("plantuml-stats.html")) {
|
||||||
try {
|
|
||||||
pw = SecurityUtils.createPrintWriter("plantuml-stats.html");
|
|
||||||
pw.print(new HtmlConverter(stats).toHtml());
|
pw.print(new HtmlConverter(stats).toHtml());
|
||||||
} finally {
|
|
||||||
if (pw != null) {
|
|
||||||
pw.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xmlOutput(Stats stats)
|
static void xmlOutput(Stats stats)
|
||||||
throws FileNotFoundException, TransformerException, ParserConfigurationException, IOException {
|
throws TransformerException, ParserConfigurationException, IOException {
|
||||||
OutputStream os = null;
|
try (OutputStream os = SecurityUtils.createFileOutputStream("plantuml-stats.xml")) {
|
||||||
try {
|
|
||||||
os = SecurityUtils.createFileOutputStream("plantuml-stats.xml");
|
|
||||||
new XmlConverter(stats).createXml(os);
|
new XmlConverter(stats).createXml(os);
|
||||||
} finally {
|
|
||||||
if (os != null) {
|
|
||||||
os.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,15 +47,9 @@ import net.sourceforge.plantuml.security.SFile;
|
|||||||
public class SvekUtils {
|
public class SvekUtils {
|
||||||
|
|
||||||
static public void traceString(final SFile f, String text) throws IOException {
|
static public void traceString(final SFile f, String text) throws IOException {
|
||||||
PrintWriter pw = null;
|
Log.info("Creating intermediate file " + f.getPrintablePath());
|
||||||
try {
|
try (PrintWriter pw = f.createPrintWriter()) {
|
||||||
Log.info("Creating intermediate file " + f.getPrintablePath());
|
|
||||||
pw = f.createPrintWriter();
|
|
||||||
pw.print(text);
|
pw.print(text);
|
||||||
} finally {
|
|
||||||
if (pw != null) {
|
|
||||||
pw.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,6 @@ import net.sourceforge.plantuml.OptionFlags;
|
|||||||
import net.sourceforge.plantuml.OptionPrint;
|
import net.sourceforge.plantuml.OptionPrint;
|
||||||
import net.sourceforge.plantuml.PlainStringsDiagram;
|
import net.sourceforge.plantuml.PlainStringsDiagram;
|
||||||
import net.sourceforge.plantuml.Run;
|
import net.sourceforge.plantuml.Run;
|
||||||
import net.sourceforge.plantuml.StringLocated;
|
|
||||||
import net.sourceforge.plantuml.core.DiagramDescription;
|
import net.sourceforge.plantuml.core.DiagramDescription;
|
||||||
import net.sourceforge.plantuml.core.UmlSource;
|
import net.sourceforge.plantuml.core.UmlSource;
|
||||||
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
|
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
|
||||||
@ -127,11 +126,8 @@ public class PSystemVersion extends PlainStringsDiagram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static BufferedImage getImageWebp(final String name) {
|
private static BufferedImage getImageWebp(final String name) {
|
||||||
try {
|
try (InputStream is = PSystemVersion.class.getResourceAsStream(name)) {
|
||||||
final InputStream is = PSystemVersion.class.getResourceAsStream(name);
|
return PSystemDedication.getBufferedImage(is);
|
||||||
final BufferedImage image = PSystemDedication.getBufferedImage(is);
|
|
||||||
is.close();
|
|
||||||
return image;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -85,28 +85,25 @@ public final class WindowsDotArchive {
|
|||||||
|
|
||||||
private static void extract(File dir) throws IOException {
|
private static void extract(File dir) throws IOException {
|
||||||
final InputStream raw = WindowsDotArchive.class.getResourceAsStream("graphviz.dat");
|
final InputStream raw = WindowsDotArchive.class.getResourceAsStream("graphviz.dat");
|
||||||
final BrotliInputStream is = new BrotliInputStream(raw);
|
try (final BrotliInputStream is = new BrotliInputStream(raw)) {
|
||||||
|
while (true) {
|
||||||
while (true) {
|
final String name = readString(is);
|
||||||
final String name = readString(is);
|
if (name.length() == 0)
|
||||||
if (name.length() == 0)
|
break;
|
||||||
break;
|
final int size = readNumber(is);
|
||||||
final int size = readNumber(is);
|
try (final OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(dir, name)))) {
|
||||||
final OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(dir, name)));
|
for (int i = 0; i < size; i++) {
|
||||||
for (int i = 0; i < size; i++) {
|
fos.write(is.read());
|
||||||
fos.write(is.read());
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fos.close();
|
|
||||||
}
|
}
|
||||||
is.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean isThereArchive() {
|
public synchronized boolean isThereArchive() {
|
||||||
if (isThereArchive == null)
|
if (isThereArchive == null)
|
||||||
try {
|
try (InputStream raw = WindowsDotArchive.class.getResourceAsStream("graphviz.dat")) {
|
||||||
final InputStream raw = WindowsDotArchive.class.getResourceAsStream("graphviz.dat");
|
|
||||||
isThereArchive = raw != null;
|
isThereArchive = raw != null;
|
||||||
raw.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
isThereArchive = false;
|
isThereArchive = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user