< prev index next >

modules/fxpackager/src/main/java/com/oracle/tools/packager/AbstractBundler.java

Print this page
rev 9619 : imported patch 9-jake-fxpackager.patch

*** 27,39 **** import com.oracle.tools.packager.windows.WindowsBundlerParam; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; ! import java.net.URL; import java.text.MessageFormat; import java.util.*; public abstract class AbstractBundler implements Bundler { --- 27,40 ---- import com.oracle.tools.packager.windows.WindowsBundlerParam; import java.io.ByteArrayOutputStream; import java.io.File; + import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; ! import java.nio.file.Files; import java.text.MessageFormat; import java.util.*; public abstract class AbstractBundler implements Bundler {
*** 56,68 **** protected void fetchResource( String publicName, String category, String defaultName, File result, boolean verbose, File publicRoot) throws IOException { ! URL u = locateResource(publicName, category, defaultName, verbose, publicRoot); ! if (u != null) { ! IOUtils.copyFromURL(u, result); } else { if (verbose) { Log.info(MessageFormat.format(I18N.getString("message.using-default-resource"), category == null ? "" : "[" + category + "] ", publicName)); } } --- 57,69 ---- protected void fetchResource( String publicName, String category, String defaultName, File result, boolean verbose, File publicRoot) throws IOException { ! InputStream is = streamResource(publicName, category, defaultName, verbose, publicRoot); ! if (is != null) { ! Files.copy(is, result.toPath()); } else { if (verbose) { Log.info(MessageFormat.format(I18N.getString("message.using-default-resource"), category == null ? "" : "[" + category + "] ", publicName)); } }
*** 70,125 **** protected void fetchResource( String publicName, String category, File defaultFile, File result, boolean verbose, File publicRoot) throws IOException { ! URL u = locateResource(publicName, category, null, verbose, publicRoot); ! if (u != null) { ! IOUtils.copyFromURL(u, result); } else { IOUtils.copyFile(defaultFile, result); if (verbose) { Log.info(MessageFormat.format(I18N.getString("message.using-custom-resource-from-file"), category == null ? "" : "[" + category + "] ", defaultFile.getAbsoluteFile())); } } } ! private URL locateResource(String publicName, String category, String defaultName, boolean verbose, File publicRoot) throws IOException { - URL u = null; boolean custom = false; if (publicName != null) { if (publicRoot != null) { File publicResource = new File(publicRoot, publicName); if (publicResource.exists() && publicResource.isFile()) { ! u = publicResource.toURI().toURL(); } } else { ! u = baseResourceLoader.getClassLoader().getResource(publicName); } ! custom = (u != null); } ! if (u == null && defaultName != null) { ! u = baseResourceLoader.getResource(defaultName); } String msg = null; if (custom) { msg = MessageFormat.format(I18N.getString("message.using-custom-resource-from-classpath"), category == null ? "" : "[" + category + "] ", publicName); ! } else if (u != null) { msg = MessageFormat.format(I18N.getString("message.using-default-resource-from-classpath"), category == null ? "" : "[" + category + "] ", publicName); } ! if (verbose && u != null) { Log.info(msg); } ! return u; } protected String preprocessTextResource(String publicName, String category, String defaultName, Map<String, String> pairs, boolean verbose, File publicRoot) throws IOException { ! URL u = locateResource(publicName, category, defaultName, verbose, publicRoot); ! InputStream inp = u.openStream(); if (inp == null) { throw new RuntimeException("Jar corrupt? No "+defaultName+" resource!"); } //read fully into memory --- 71,125 ---- protected void fetchResource( String publicName, String category, File defaultFile, File result, boolean verbose, File publicRoot) throws IOException { ! InputStream is = streamResource(publicName, category, null, verbose, publicRoot); ! if (is != null) { ! Files.copy(is, result.toPath()); } else { IOUtils.copyFile(defaultFile, result); if (verbose) { Log.info(MessageFormat.format(I18N.getString("message.using-custom-resource-from-file"), category == null ? "" : "[" + category + "] ", defaultFile.getAbsoluteFile())); } } } ! private InputStream streamResource(String publicName, String category, String defaultName, boolean verbose, File publicRoot) throws IOException { boolean custom = false; + InputStream is = null; if (publicName != null) { if (publicRoot != null) { File publicResource = new File(publicRoot, publicName); if (publicResource.exists() && publicResource.isFile()) { ! is = new FileInputStream(publicResource); } } else { ! is = baseResourceLoader.getClassLoader().getResourceAsStream(publicName); } ! custom = (is != null); } ! if (is == null && defaultName != null) { ! is = baseResourceLoader.getResourceAsStream(defaultName); } String msg = null; if (custom) { msg = MessageFormat.format(I18N.getString("message.using-custom-resource-from-classpath"), category == null ? "" : "[" + category + "] ", publicName); ! } else if (is != null) { msg = MessageFormat.format(I18N.getString("message.using-default-resource-from-classpath"), category == null ? "" : "[" + category + "] ", publicName); } ! if (verbose && is != null) { Log.info(msg); } ! return is; } protected String preprocessTextResource(String publicName, String category, String defaultName, Map<String, String> pairs, boolean verbose, File publicRoot) throws IOException { ! InputStream inp = streamResource(publicName, category, defaultName, verbose, publicRoot); if (inp == null) { throw new RuntimeException("Jar corrupt? No "+defaultName+" resource!"); } //read fully into memory
< prev index next >