Mega Code Archive
Retreive Text File From Jar
/*
* Copyright 2006 - 2008 Georges Stephan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.logging.*;
import java.io.*;
/**
*
* @author Georges Stephan
*/
public class Util {
private static Logger logger = Logger.getLogger(Util.class.getName());
public static String validateString(String aString) {
if(aString==null) return("");
aString=aString.replace('\'', ' ');
aString=aString.trim();
return(aString);
}
public static String removeNonDigits(String aString) {
StringBuffer newString = new StringBuffer();
for(int x=0;x0) {
FileWriter temp = new FileWriter(targetDirectory+File.separator+resourceName);
temp.write(sb.toString());
temp.close();
found=true;
}
}
}
return(found);
}
public static boolean retreiveBinaryFileFromJar(String resourceName,String targetDirectory,Object resource) throws Exception {
boolean found=false;
if(resourceName!=null) {
InputStream is = resource.getClass().getResourceAsStream(resourceName);
if(is==null) throw new Exception ("Resource "+resourceName+" was not found.");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
FileOutputStream fos = new FileOutputStream(targetDirectory+File.separator+resourceName.substring(resourceName.lastIndexOf('/'),resourceName.length()));
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead);
}
fos.flush();
br.close();
is.close();
found=true;
} else {
found=false;
}
return found;
}
}