theSet) {
String[] theArray = theSet.toArray(new String[theSet.size()]);
Collator collator = Collator.getInstance();
Arrays.sort(theArray, collator);
return theArray;
}
/* Utility method that url encodes a string */
public static String urlEncode(String s) {
try {
return URLEncoder.encode(s,"UTF-8");
}
catch (UnsupportedEncodingException e) {
return "";
}
}
/* Utility method that url decodes a string */
public static String urlDecode(String s) {
try {
return URLDecoder.decode(s,"UTF-8");
}
catch (UnsupportedEncodingException e) {
return "";
}
}
/* utility method to make a file name valid for a href attribute
(ie. replace spaces with %20 etc.)
*/
public static String makeHref(String s) {
try {
URI uri = new URI(null, null, s, null);
return uri.toString();
}
catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/* utility method to convert a *relative* URL to a file name
(ie. replace %20 with spaces etc.)
*/
public static String makeFileName(String sURL) {
try {
File file = new File(new java.net.URI("file:///"+sURL));
return file.getName();
}
catch (Exception e) {
e.printStackTrace();
}
return "error";
}
public static File urlToFile(String sUrl) {
try {
return new File(new URI(sUrl));
}
catch (URISyntaxException e) {
return new File(".");
}
}
/** Read an InputStream
into a byte
array
* @param is the InputStream
to read
* @return a byte array with the contents read from the stream
* @throws IOException in case of any I/O errors.
*/
public static byte[] inputStreamToByteArray(InputStream is) throws IOException {
if (is==null) {
throw new IOException ("No input stream to read");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int nLen = 0;
byte buffer[] = new byte[BUFFERSIZE];
while ((nLen = is.read(buffer)) > 0) {
baos.write(buffer, 0, nLen);
}
return baos.toByteArray();
}
public static final int getPosInteger(String sInteger, int nDefault){
int n;
try {
n=Integer.parseInt(sInteger);
}
catch (NumberFormatException e) {
return nDefault;
}
return n>0 ? n : nDefault;
}
}