Corrected and removed redundant error messages on resources not found.
This commit is contained in:
parent
ebe02870df
commit
f29dae18c6
@ -96,17 +96,31 @@ public class EvAInfo {
|
||||
try {
|
||||
EVA_PROPERTIES = BasicResourceLoader.readProperties(EvAInfo.propertyFile);
|
||||
} catch (Exception ex) {
|
||||
System.err.println("ERROR! Could not read the configuration file "+ EvAInfo.propertyFile);
|
||||
System.err.println(resourceNotFoundErrorMessage(EvAInfo.propertyFile));
|
||||
System.err.println(ex.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
File f=new File(EvAInfo.iconLocation);
|
||||
if (!f.exists()) {
|
||||
System.err.println("Error: Could not find EvA2 resources. Did you copy the resources folder to working directory? (EvAInfo.static)");
|
||||
throw new RuntimeException(resourceNotFoundErrorMessage(EvAInfo.iconLocation) + " (EvAInfo.static)");
|
||||
// System.exit(2); // dont be as harsh right here - there will be plenty of exceptions later in the bad case...
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An eloquent error message in case a resource was not found - which was
|
||||
* expected in the EvA2 resource directory.
|
||||
* @param resourceName
|
||||
* @return
|
||||
*/
|
||||
public static String resourceNotFoundErrorMessage(String resourceName) {
|
||||
String cp = System.getProperty("java.class.path");
|
||||
return "Could not find " + resourceName +
|
||||
"\nPlease make resources folder available on the class path! " +
|
||||
"Current class path is: " + cp +
|
||||
"\nYou may copy it there or add the parent folder of resources/ to the class path.";
|
||||
}
|
||||
|
||||
public static String getProperty(String key) {
|
||||
String myVal = EVA_PROPERTIES.getProperty(key);
|
||||
return myVal;
|
||||
|
@ -282,12 +282,8 @@ public class EvAClient implements RemoteStateListener, Serializable {
|
||||
if (withGUI ) {
|
||||
m_Frame = new JEFrame(EvAInfo.productName + " workbench");
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation);
|
||||
try {
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
|
||||
m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.err.println("Could not find EvA2 icon, please move resources folder to working directory!");
|
||||
}
|
||||
// m_Frame.setTitle(EvAInfo.productName + " workbench");
|
||||
|
||||
try {
|
||||
@ -986,8 +982,7 @@ class SplashScreen extends Frame {
|
||||
public void splash(){
|
||||
JWindow splashWindow = new JWindow(this);
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(imgLocation);
|
||||
try {
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true);
|
||||
ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
JLabel splashLabel = new JLabel(ii);
|
||||
splashWindow.add(splashLabel);
|
||||
@ -995,9 +990,6 @@ class SplashScreen extends Frame {
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2);
|
||||
splashWindow.setVisible(true);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.err.println("Could not find EvA2 splash screen, please move resources folder to working directory!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -174,13 +174,8 @@ public class GenericOptimizationObjectivesEditor extends JPanel implements Prope
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true);
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Sub24 icon, please move resources folder to working directory!");
|
||||
this.m_Delete[i] = new JButton("Sub");
|
||||
}
|
||||
this.m_Delete[i].addActionListener(deleteTarget);
|
||||
this.m_TargetList.add(this.m_Delete[i], gbc);
|
||||
}
|
||||
|
@ -198,13 +198,8 @@ public class GenericOptimizationObjectivesWithParamEditor extends JPanel impleme
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 1;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true);
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find Sub24 icon, please move resources folder to working directory!");
|
||||
this.m_Delete[i] = new JButton("Sub");
|
||||
}
|
||||
this.m_Delete[i].addActionListener(deleteTarget);
|
||||
this.m_TargetList.add(this.m_Delete[i], gbc);
|
||||
}
|
||||
|
@ -111,13 +111,9 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor
|
||||
private JButton makeButtonWith(String iconSrc, String title) {
|
||||
JButton tmpB;
|
||||
byte[] bytes;
|
||||
bytes = BasicResourceLoader.instance().getBytesFromResourceLocation(iconSrc);
|
||||
try {
|
||||
tmpB = new JButton(title, new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.err.println("Could not find icon " + iconSrc + ", please move resources folder to working directory!");
|
||||
tmpB = new JButton(title);
|
||||
}
|
||||
bytes = BasicResourceLoader.instance().getBytesFromResourceLocation(iconSrc, false);
|
||||
if (bytes!=null) tmpB = new JButton(title, new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
else tmpB = new JButton(title);
|
||||
return tmpB;
|
||||
}
|
||||
|
||||
@ -172,7 +168,7 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor
|
||||
this.m_ServerList.add(this.m_CPUs[i], gbc);
|
||||
// The delete button
|
||||
setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.REMAINDER, 3, 10);
|
||||
bytes = BasicResourceLoader.instance().getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
bytes = BasicResourceLoader.instance().getBytesFromResourceLocation("resources/images/Sub24.gif", true);
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
this.m_Delete[i].addActionListener(deleteServer);
|
||||
this.m_ServerList.add(this.m_Delete[i], gbc);
|
||||
|
@ -94,12 +94,8 @@ public class HtmlDemo {
|
||||
}
|
||||
JFrame frame = new JFrame (m_name);
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation);
|
||||
try {
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
|
||||
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.err.println("Could not find EvA2 icon, please move resources folder to working directory!");
|
||||
}
|
||||
JScrollPane scroller = new JScrollPane();
|
||||
JViewport vp = scroller.getViewport();
|
||||
vp.add(m_html);
|
||||
|
@ -107,12 +107,9 @@ Serializable {
|
||||
m_TextArea.setCaretPosition(0);
|
||||
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation);
|
||||
try {
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
|
||||
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find EvA2 icon, please move resources folder to working directory!");
|
||||
}
|
||||
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
frame.dispose();
|
||||
|
@ -105,12 +105,8 @@ public class LogPanel extends JPanel {
|
||||
final JFrame frame = new JFrame("Log_Panel_Test");
|
||||
frame.getContentPane().setLayout(new BorderLayout());
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation);
|
||||
try {
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
|
||||
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find EvA2 icon, please move resources folder to working directory!");
|
||||
}
|
||||
LogPanel panel = new LogPanel();
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
|
@ -221,16 +221,8 @@ public class Plot implements PlotInterface, Serializable {
|
||||
public void init() {
|
||||
m_Frame = new JEFrame("Plot: " + m_PlotName);
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader
|
||||
.getBytesFromResourceLocation(EvAInfo.iconLocation);
|
||||
try {
|
||||
m_Frame
|
||||
.setIconImage(Toolkit.getDefaultToolkit()
|
||||
.createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.err
|
||||
.println("Could not find EvA2 icon, please move resources folder to working directory!");
|
||||
}
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
|
||||
m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
|
||||
m_ButtonPanel = new JPanel();
|
||||
m_PlotArea = new FunctionArea(m_xname, m_yname);
|
||||
|
@ -35,12 +35,9 @@ public class PropertyDialog extends JEFrame {
|
||||
public PropertyDialog (PropertyEditor editor,String Title, int x, int y) {
|
||||
super(getFrameNameFromEditor(editor)); // that was the long class name !!
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation);
|
||||
try {
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
|
||||
setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.err.println("Could not find EvA2 icon, please move resources folder to working directory!");
|
||||
}
|
||||
|
||||
//System.out.println("PropertyDialog.Constructor of "+ Title);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
|
@ -126,12 +126,8 @@ public class TagEditor extends PropertyEditorSupport {
|
||||
PropertyValueSelector ps = new PropertyValueSelector(ce);
|
||||
JFrame f = new JFrame();
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation);
|
||||
try {
|
||||
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
|
||||
f.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find EvA2 icon, please move resources folder to working directory!");
|
||||
}
|
||||
f.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
|
@ -55,14 +55,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.weightx = 100;
|
||||
tmpB = new JButton();
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_MOEA.gif");
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_MOEA.gif", true);
|
||||
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
tmpB.setBackground(Color.WHITE);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find MOCCO_MOEA icon, please move resources folder to working directory!");
|
||||
tmpB.setText("Multi-Objective EA");
|
||||
}
|
||||
gbc.gridy = 0;
|
||||
gbc.gridx = 0;
|
||||
tmpP.add(tmpB, gbc);
|
||||
@ -78,14 +73,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
|
||||
" objectives."), gbc);
|
||||
|
||||
tmpB = new JButton();
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_GDF.gif");
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_GDF.gif", true);
|
||||
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
tmpB.setBackground(Color.WHITE);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find MOCCO_GDF icon, please move resources folder to working directory!");
|
||||
tmpB.setText("Geoffrion-Dyer-Feinberg Meth.");
|
||||
}
|
||||
gbc.gridy = 1;
|
||||
gbc.gridx = 0;
|
||||
tmpP.add(tmpB, gbc);
|
||||
@ -99,14 +89,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
|
||||
this.m_Mocco.m_JPanelParameters.add(tmpP, BorderLayout.CENTER);
|
||||
|
||||
tmpB = new JButton();
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_STEP.gif");
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_STEP.gif", true);
|
||||
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
tmpB.setBackground(Color.WHITE);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find MOCCO_STEP icon, please move resources folder to working directory!");
|
||||
tmpB.setText("STEP Method");
|
||||
}
|
||||
gbc.gridy = 2;
|
||||
gbc.gridx = 0;
|
||||
tmpP.add(tmpB, gbc);
|
||||
@ -121,14 +106,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
|
||||
" into a single objectives. The individual weights are also to be given by the DM."), gbc);
|
||||
|
||||
tmpB = new JButton();
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_REFP.gif");
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_REFP.gif", true);
|
||||
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
tmpB.setBackground(Color.WHITE);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find MOCCO_REFP icon, please move resources folder to working directory!");
|
||||
tmpB.setText("Reference Point Method");
|
||||
}
|
||||
gbc.gridy = 3;
|
||||
gbc.gridx = 0;
|
||||
tmpP.add(tmpB, gbc);
|
||||
@ -143,14 +123,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
|
||||
" same time."), gbc);
|
||||
|
||||
tmpB = new JButton();
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_TBCH.gif");
|
||||
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_TBCH.gif", true);
|
||||
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
tmpB.setBackground(Color.WHITE);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find MOCCO_TBCH icon, please move resources folder to working directory!");
|
||||
tmpB.setText("Tchebycheff Method");
|
||||
}
|
||||
gbc.gridy = 4;
|
||||
gbc.gridx = 0;
|
||||
tmpB.addActionListener(choosenTBCH);
|
||||
|
@ -50,32 +50,6 @@ public abstract class MOCCOPhase implements InterfaceProcessElement {
|
||||
}
|
||||
};
|
||||
|
||||
// /** Fetch the alternatives for a given class
|
||||
// * @param type The class to test
|
||||
// * @return The class alternatives
|
||||
// */
|
||||
// public Vector getClassAlternatives4(String type) {
|
||||
// String typeOptions = EvAClient.getProperty(type);
|
||||
// Vector classes = new Vector();
|
||||
// StringTokenizer st = new StringTokenizer(typeOptions, ", ");
|
||||
// while (st.hasMoreTokens()) {
|
||||
// String current = st.nextToken().trim();
|
||||
// try {
|
||||
// try {
|
||||
// Class c = Class.forName(current);
|
||||
// classes.addElement(current);
|
||||
// } catch (java.lang.ClassNotFoundException et) {
|
||||
// System.out.println("Could not find class for value " + current + " for type " + type);
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// System.out.println("Couldn't load class with name: " + current + " for type " + type);
|
||||
// System.out.println("ex:"+ex.getMessage());
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// return classes;
|
||||
// }
|
||||
|
||||
/** This method makes a helptext element similar to that used in EvA
|
||||
* @param help The text to display
|
||||
* @return the helptext component
|
||||
|
@ -201,13 +201,8 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 1;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true);
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find sub24 icon, please move resources folder to working directory!");
|
||||
this.m_Delete[i] = new JButton("Sub");
|
||||
}
|
||||
this.m_Delete[i].addActionListener(deleteTarget);
|
||||
this.m_TargetList.add(this.m_Delete[i], gbc);
|
||||
}
|
||||
|
@ -176,13 +176,8 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
|
||||
gbc.fill = GridBagConstraints.REMAINDER;
|
||||
gbc.gridx = 2;
|
||||
gbc.weightx = 1;
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif");
|
||||
try {
|
||||
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true);
|
||||
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
System.out.println("Could not find sub24 icon, please move resources folder to working directory!");
|
||||
this.m_Delete[i] = new JButton("Sub");
|
||||
}
|
||||
this.m_Delete[i].addActionListener(deleteTarget);
|
||||
this.m_TargetList.add(this.m_Delete[i], gbc);
|
||||
}
|
||||
|
@ -37,17 +37,17 @@ public class FileTools {
|
||||
static public String[] loadStringsFromFile(String file) {
|
||||
String[] result = null;
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte bytes[] = loader.getBytesFromResourceLocation(file);
|
||||
byte bytes[] = loader.getBytesFromResourceLocation(file, false);
|
||||
if (bytes != null) {
|
||||
String data = new String(bytes);
|
||||
result = data.split("\n");
|
||||
} else {
|
||||
System.out.println("BasicResourceLoader failed to read "+file);
|
||||
System.err.println("BasicResourceLoader failed to read "+file);
|
||||
BufferedReader reader= null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
} catch (java.io.FileNotFoundException e) {
|
||||
System.out.println("Could not find " + file);
|
||||
System.err.println("Could not find " + file);
|
||||
return result;
|
||||
}
|
||||
String currentLine;
|
||||
@ -63,7 +63,7 @@ public class FileTools {
|
||||
}
|
||||
reader.close();
|
||||
} catch (java.io.IOException e) {
|
||||
System.out.println("Java.io.IOExeption: " + e.getMessage());
|
||||
System.err.println("Java.io.IOExeption: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -43,6 +43,8 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import eva2.EvAInfo;
|
||||
|
||||
|
||||
/**
|
||||
* Loads resource file from directory OR jar file. Now it is easier possible to
|
||||
@ -117,13 +119,13 @@ public class BasicResourceLoader implements ResourceLoader
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
* Read String lines from a file into a list.
|
||||
*
|
||||
* @param resourceFile Description of the Parameter
|
||||
* @param resourceFile File to read
|
||||
* @param ignorePrefix array of prefixes which mark a line to be ignored
|
||||
* @param lOffset offset of the first line to read
|
||||
* @param lCnt number of lines to read, if <= 0, all lines are read
|
||||
* @return Description of the Return Value
|
||||
* @return List of lines which were read or null on an error
|
||||
*/
|
||||
public static List<String> readLines(String resourceFile,
|
||||
String[] ignorePrefix, int lOffset, int lCnt)
|
||||
@ -135,7 +137,7 @@ public class BasicResourceLoader implements ResourceLoader
|
||||
|
||||
byte[] bytes = BasicResourceLoader.instance()
|
||||
.getBytesFromResourceLocation(
|
||||
resourceFile);
|
||||
resourceFile, false);
|
||||
|
||||
if (bytes == null)
|
||||
{
|
||||
@ -382,21 +384,34 @@ public class BasicResourceLoader implements ResourceLoader
|
||||
// }
|
||||
// return getStreamFromFile(found.get(0));
|
||||
// }
|
||||
|
||||
/**
|
||||
* Gets the byte data from a file at the given resource location.
|
||||
*
|
||||
* @param rawResrcLoc Description of the Parameter
|
||||
* @return the byte array of file.
|
||||
*/
|
||||
public byte[] getBytesFromResourceLocation(String rawResrcLoc)
|
||||
public byte[] getBytesFromResourceLocation(String rawResrcLoc) {
|
||||
return getBytesFromResourceLocation(rawResrcLoc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the byte data from a file at the given resource location.
|
||||
*
|
||||
* @param rawResrcLoc Location of the resource
|
||||
* @param exceptionOnNotFound if true, a RuntimeException is thrown if the resource was not found.
|
||||
* @return the byte array of file.
|
||||
*/
|
||||
public byte[] getBytesFromResourceLocation(String rawResrcLoc, boolean exceptionOnNotFound)
|
||||
{
|
||||
InputStream in = getStreamFromResourceLocation(rawResrcLoc);
|
||||
|
||||
if (in == null) {
|
||||
return null;
|
||||
byte[] arr = null;
|
||||
if (in != null) {
|
||||
arr = getBytesFromStream(in);
|
||||
}
|
||||
return getBytesFromStream(in);
|
||||
if (exceptionOnNotFound && (arr==null)) {
|
||||
throw new RuntimeException(EvAInfo.resourceNotFoundErrorMessage(rawResrcLoc));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -621,7 +636,7 @@ public class BasicResourceLoader implements ResourceLoader
|
||||
Properties prop = new Properties();
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
|
||||
byte bytes[] = loader.getBytesFromResourceLocation(resourceName);
|
||||
byte bytes[] = loader.getBytesFromResourceLocation(resourceName, false);
|
||||
if (bytes != null) {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||
prop.load(bais);
|
||||
|
@ -12,12 +12,9 @@ package eva2.tools;
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
@ -25,8 +22,6 @@ import java.net.InetAddress;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import eva2.client.EvAClient;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@ -36,38 +31,6 @@ public class EVAHELP {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static public Properties readProperties(String resourceName) throws Exception {
|
||||
if (EvAClient.TRACE) System.out.println("readProperties of file: " + resourceName);
|
||||
Properties prop = new Properties();
|
||||
BasicResourceLoader loader = BasicResourceLoader.instance();
|
||||
byte bytes[] = loader.getBytesFromResourceLocation(resourceName);
|
||||
if (bytes != null) {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||
prop.load(bais);
|
||||
}
|
||||
if (prop != null)
|
||||
return prop;
|
||||
/////////////
|
||||
|
||||
int slInd = resourceName.lastIndexOf('/');
|
||||
if (slInd != -1)
|
||||
resourceName = resourceName.substring(slInd + 1);
|
||||
Properties userProps = new Properties();
|
||||
File propFile = new File(File.separatorChar + "resources" +
|
||||
File.separatorChar + resourceName);
|
||||
if (propFile.exists()) {
|
||||
try {
|
||||
userProps.load(new FileInputStream(propFile));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
System.out.println("Problem reading user properties: " + propFile);
|
||||
}
|
||||
}
|
||||
return userProps;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user