From 74c11dcec9338c2656a94f9f5dcb7693572a3962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 14 Apr 2014 20:34:27 +0200 Subject: [PATCH] cleanup --- .../gamecore/render/fonts/impl/CachedFont.java | 6 ++++-- .../gamecore/render/fonts/impl/DeferredFont.java | 2 +- src/mightypork/test/TestCoords.java | 14 +++++++------- src/mightypork/test/TestVec.java | 6 +++--- src/mightypork/utils/config/PropertyManager.java | 2 +- src/mightypork/utils/files/FileTreeDiff.java | 6 ++++-- src/mightypork/utils/files/FileUtils.java | 12 +++++++----- src/mightypork/utils/files/ZipBuilder.java | 4 ++-- src/mightypork/utils/files/ZipUtils.java | 11 +++++++---- src/mightypork/utils/files/ion/Ion.java | 4 ++-- 10 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/mightypork/gamecore/render/fonts/impl/CachedFont.java b/src/mightypork/gamecore/render/fonts/impl/CachedFont.java index cf301ea..0908260 100644 --- a/src/mightypork/gamecore/render/fonts/impl/CachedFont.java +++ b/src/mightypork/gamecore/render/fonts/impl/CachedFont.java @@ -294,7 +294,8 @@ public class CachedFont implements GLFont { byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI); } else { - byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData()); + byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()) + .put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData()); } byteBuffer.flip(); @@ -411,7 +412,8 @@ public class CachedFont implements GLFont { chtx = chars.get(charCurrent); if (chtx != null) { - drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY + chtx.height); + drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY + + chtx.height); totalwidth += chtx.width; } } diff --git a/src/mightypork/gamecore/render/fonts/impl/DeferredFont.java b/src/mightypork/gamecore/render/fonts/impl/DeferredFont.java index afa3658..d8aaade 100644 --- a/src/mightypork/gamecore/render/fonts/impl/DeferredFont.java +++ b/src/mightypork/gamecore/render/fonts/impl/DeferredFont.java @@ -129,7 +129,7 @@ public class DeferredFont extends DeferredResource implements GLFont { */ protected Font getAwtFont(String resource, float size, int style) throws FontFormatException, IOException { - try (InputStream in = FileUtils.getResource(resource)) { + try(InputStream in = FileUtils.getResource(resource)) { Font awtFont = Font.createFont(Font.TRUETYPE_FONT, in); diff --git a/src/mightypork/test/TestCoords.java b/src/mightypork/test/TestCoords.java index 4bb9e79..a3ebcb1 100644 --- a/src/mightypork/test/TestCoords.java +++ b/src/mightypork/test/TestCoords.java @@ -12,13 +12,13 @@ public class TestCoords { public static void main(String[] args) { { - VectVar a = Vect.makeVar(); - VectVar b = Vect.makeVar(); + final VectVar a = Vect.makeVar(); + final VectVar b = Vect.makeVar(); - Vect cross = a.cross(b); - Num dot = a.dot(b); - Vect sum = a.add(b); - Num dist = a.dist(b); + final Vect cross = a.cross(b); + final Num dot = a.dot(b); + final Vect sum = a.add(b); + final Num dist = a.dist(b); a.setTo(0, 10, 0); b.setTo(0, 6, 7); @@ -32,7 +32,7 @@ public class TestCoords { } { - NumVar a = Num.makeVar(); + final NumVar a = Num.makeVar(); Num end = a; diff --git a/src/mightypork/test/TestVec.java b/src/mightypork/test/TestVec.java index c402a1e..5bc28bf 100644 --- a/src/mightypork/test/TestVec.java +++ b/src/mightypork/test/TestVec.java @@ -10,16 +10,16 @@ public class TestVec { public static void main(String[] args) { - VectVar a = Vect.makeVar(-100, 12, 6); + final VectVar a = Vect.makeVar(-100, 12, 6); - VectConst b = a.freeze(); + final VectConst b = a.freeze(); a.setTo(400, 400, 300); System.out.println(a); System.out.println(b); - Vect c = a.abs().neg(); + final Vect c = a.abs().neg(); System.out.println(c); diff --git a/src/mightypork/utils/config/PropertyManager.java b/src/mightypork/utils/config/PropertyManager.java index 6574ab7..9e642ae 100644 --- a/src/mightypork/utils/config/PropertyManager.java +++ b/src/mightypork/utils/config/PropertyManager.java @@ -179,7 +179,7 @@ public class PropertyManager { } } - try (FileInputStream fis = new FileInputStream(file)) { + try(FileInputStream fis = new FileInputStream(file)) { props.load(fis); } catch (final IOException e) { needsSave = true; diff --git a/src/mightypork/utils/files/FileTreeDiff.java b/src/mightypork/utils/files/FileTreeDiff.java index 6573e1d..6f427ba 100644 --- a/src/mightypork/utils/files/FileTreeDiff.java +++ b/src/mightypork/utils/files/FileTreeDiff.java @@ -72,9 +72,11 @@ public class FileTreeDiff { ck1.reset(); ck2.reset(); - try (FileInputStream in1 = new FileInputStream(pair.a); FileInputStream in2 = new FileInputStream(pair.b)) { + try(FileInputStream in1 = new FileInputStream(pair.a); + FileInputStream in2 = new FileInputStream(pair.b)) { - try (CheckedInputStream cin1 = new CheckedInputStream(in1, ck1); CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) { + try(CheckedInputStream cin1 = new CheckedInputStream(in1, ck1); + CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) { while (true) { final int read1 = cin1.read(BUFFER); diff --git a/src/mightypork/utils/files/FileUtils.java b/src/mightypork/utils/files/FileUtils.java index dc6de22..b6c2ce2 100644 --- a/src/mightypork/utils/files/FileUtils.java +++ b/src/mightypork/utils/files/FileUtils.java @@ -95,7 +95,8 @@ public class FileUtils { public static void copyFile(File source, File target) throws IOException { - try (InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(target)) { + try(InputStream in = new FileInputStream(source); + OutputStream out = new FileOutputStream(target)) { copyStream(in, out); } @@ -160,7 +161,7 @@ public class FileUtils { */ public static String fileToString(File file) throws IOException { - try (FileInputStream fin = new FileInputStream(file)) { + try(FileInputStream fin = new FileInputStream(file)) { return streamToString(fin); } @@ -360,7 +361,7 @@ public class FileUtils { */ public static void stringToFile(File file, String text) throws IOException { - try (PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) { + try(PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) { out.print(text); @@ -481,7 +482,8 @@ public class FileUtils { */ public static void resourceToFile(String resname, File file) throws IOException { - try (InputStream in = FileUtils.getResource(resname); OutputStream out = new FileOutputStream(file)) { + try(InputStream in = FileUtils.getResource(resname); + OutputStream out = new FileOutputStream(file)) { FileUtils.copyStream(in, out); } @@ -498,7 +500,7 @@ public class FileUtils { */ public static String resourceToString(String resname) throws IOException { - try (InputStream in = FileUtils.getResource(resname)) { + try(InputStream in = FileUtils.getResource(resname)) { return streamToString(in); } } diff --git a/src/mightypork/utils/files/ZipBuilder.java b/src/mightypork/utils/files/ZipBuilder.java index af33bc0..875baa6 100644 --- a/src/mightypork/utils/files/ZipBuilder.java +++ b/src/mightypork/utils/files/ZipBuilder.java @@ -74,7 +74,7 @@ public class ZipBuilder { out.putNextEntry(new ZipEntry(path)); - try (InputStream in = FileUtils.stringToStream(text)) { + try(InputStream in = FileUtils.stringToStream(text)) { FileUtils.copyStream(in, out); } } @@ -95,7 +95,7 @@ public class ZipBuilder { out.putNextEntry(new ZipEntry(path)); - try (InputStream in = FileUtils.getResource(resPath)) { + try(InputStream in = FileUtils.getResource(resPath)) { FileUtils.copyStream(in, out); } } diff --git a/src/mightypork/utils/files/ZipUtils.java b/src/mightypork/utils/files/ZipUtils.java index 10a443b..faa330d 100644 --- a/src/mightypork/utils/files/ZipUtils.java +++ b/src/mightypork/utils/files/ZipUtils.java @@ -33,7 +33,7 @@ public class ZipUtils { */ public static List extractZip(File file, File outputDir, StringFilter filter) throws IOException { - try (ZipFile zip = new ZipFile(file)) { + try(ZipFile zip = new ZipFile(file)) { return extractZip(zip, outputDir, filter); } } @@ -89,7 +89,7 @@ public class ZipUtils { */ public static List listZip(File zipFile) throws IOException { - try (ZipFile zip = new ZipFile(zipFile)) { + try(ZipFile zip = new ZipFile(zipFile)) { return listZip(zip); } } @@ -133,7 +133,10 @@ public class ZipUtils { { if (!destFile.getParentFile().mkdirs()) throw new IOException("Could not create output directory."); - try (InputStream in = zip.getInputStream(entry); BufferedInputStream is = new BufferedInputStream(in); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) { + try(InputStream in = zip.getInputStream(entry); + BufferedInputStream is = new BufferedInputStream(in); + FileOutputStream fos = new FileOutputStream(destFile); + BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) { FileUtils.copyStream(is, dest); } @@ -167,7 +170,7 @@ public class ZipUtils { public static boolean entryExists(File selectedFile, String string) { - try (ZipFile zf = new ZipFile(selectedFile)) { + try(ZipFile zf = new ZipFile(selectedFile)) { return zf.getEntry(string) != null; } catch (final IOException | RuntimeException e) { Log.w("Error reading zip.", e); diff --git a/src/mightypork/utils/files/ion/Ion.java b/src/mightypork/utils/files/ion/Ion.java index 26b6a9a..3d0dbb6 100644 --- a/src/mightypork/utils/files/ion/Ion.java +++ b/src/mightypork/utils/files/ion/Ion.java @@ -67,7 +67,7 @@ public class Ion { */ public static Object fromFile(File file) throws IonException { - try (InputStream in = new FileInputStream(file)) { + try(InputStream in = new FileInputStream(file)) { final Object obj = fromStream(in); return obj; @@ -113,7 +113,7 @@ public class Ion { */ public static void toFile(File path, Object obj) throws IonException { - try (OutputStream out = new FileOutputStream(path)) { + try(OutputStream out = new FileOutputStream(path)) { final String f = path.toString(); final File dir = new File(f.substring(0, f.lastIndexOf(File.separator)));