public class Util extends Object
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static void |
cleanup(Object o)
Closes the object (connection, stream etc.) without throwing any exception, even if the
object is null
|
static void |
copy(InputStream i,
OutputStream o)
Copy the input stream into the output stream, closes both streams when finishing or in
a case of an exception
|
static void |
copy(InputStream i,
OutputStream o,
int bufferSize)
Copy the input stream into the output stream, closes both streams when finishing or in
a case of an exception
|
static String |
decode(String s,
String enc,
boolean plusToSpace)
Decodes a String URL encoded URL
|
static boolean |
downloadUrlToFile(String url,
String fileName,
boolean showProgress)
Blocking method that will download the given URL to the file system storage and return when the
operation completes
|
static void |
downloadUrlToFileSystemInBackground(String url,
String fileName)
Non-blocking method that will download the given URL to file system storage in the background and return immediately
|
static void |
downloadUrlToFileSystemInBackground(String url,
String fileName,
ActionListener onCompletion)
Non-blocking method that will download the given URL to file system storage in the background and return immediately
|
static boolean |
downloadUrlToStorage(String url,
String fileName,
boolean showProgress)
Blocking method that will download the given URL to storage and return when the
operation completes
|
static void |
downloadUrlToStorageInBackground(String url,
String fileName)
Non-blocking method that will download the given URL to storage in the background and return immediately
|
static void |
downloadUrlToStorageInBackground(String url,
String fileName,
ActionListener onCompletion)
Non-blocking method that will download the given URL to storage in the background and return immediately
|
static String |
encodeBody(byte[] buf)
Deprecated.
use encodeUrl(char[]) instead
|
static String |
encodeBody(char[] buf)
Encode a string for HTML post requests matching the style used in application/x-www-form-urlencoded
|
static String |
encodeBody(String str)
Encode a string for HTML post requests matching the style used in application/x-www-form-urlencoded
|
static String |
encodeUrl(byte[] buf)
Deprecated.
use encodeUrl(char[]) instead
|
static String |
encodeUrl(char[] buf)
Encode a string for HTML requests
|
static String |
encodeUrl(String str)
Encode a string for HTML requests
|
static String |
getIgnorCharsWhileEncoding()
These chars will not be encoded by the encoding method in this class
as requested in RFE 427 http://java.net/jira/browse/LWUIT-427
|
static String |
getURLBasePath(String url)
Returns the URL's base path, which is the same as the path only without an ending file e.g.:
http://domain.com/f/f.html would return as: /f/
|
static String |
getURLHost(String url)
Returns the URL's host portion
|
static String |
getURLPath(String url)
Returns the URL's path
|
static String |
getURLProtocol(String url)
Returns the protocol of an absolute URL e.g.
|
static boolean |
instanceofByteArray(Object o)
Deprecated.
this method serves as a temporary workaround for an XMLVM bug and will be removed
once the bug is fixed
|
static boolean |
instanceofDoubleArray(Object o)
Deprecated.
this method serves as a temporary workaround for an XMLVM bug and will be removed
once the bug is fixed
|
static boolean |
instanceofFloatArray(Object o)
Deprecated.
this method serves as a temporary workaround for an XMLVM bug and will be removed
once the bug is fixed
|
static boolean |
instanceofIntArray(Object o)
Deprecated.
this method serves as a temporary workaround for an XMLVM bug and will be removed
once the bug is fixed
|
static boolean |
instanceofLongArray(Object o)
Deprecated.
this method serves as a temporary workaround for an XMLVM bug and will be removed
once the bug is fixed
|
static boolean |
instanceofObjArray(Object o)
Deprecated.
this method serves as a temporary workaround for an XMLVM bug and will be removed
once the bug is fixed
|
static boolean |
instanceofShortArray(Object o)
Deprecated.
this method serves as a temporary workaround for an XMLVM bug and will be removed
once the bug is fixed
|
static void |
mergeArrays(Object[] arr1,
Object[] arr2,
Object[] destinationArray)
Merges arrays into one larger array
|
static int |
readAll(InputStream i,
byte[] b)
Reads until the array is full or until the stream ends
|
static void |
readFully(InputStream i,
byte[] b)
The read fully method from data input stream is very useful for all types of
streams...
|
static void |
readFully(InputStream i,
byte[] b,
int off,
int len)
The read fully method from data input stream is very useful for all types of
streams...
|
static byte[] |
readInputStream(InputStream i)
Converts a small input stream to a byte array
|
static Object |
readObject(DataInputStream input)
Reads an object from the stream
|
static String |
readToString(InputStream i)
Reads an input stream to a string
|
static String |
readToString(InputStream i,
String encoding)
Reads an input stream to a string
|
static String |
readUTF(DataInputStream d)
Reads a UTF string that may be null previously written by writeUTF
|
static void |
register(Externalizable e)
Registers this externalizable so readObject will be able to load such objects
|
static void |
register(String id,
Class c)
Registers this externalizable so readObject will be able to load such objects
|
static String |
relativeToAbsolute(String baseURL,
String relativeURL)
Converts a relative url e.g.: /myfile.html to an absolute url
|
static void |
setIgnorCharsWhileEncoding(String s)
These chars will not be encoded by the encoding method in this class
as requested in RFE 427 http://java.net/jira/browse/LWUIT-427
|
static void |
setImplementation(CodenameOneImplementation impl)
Invoked internally from Display, this method is for internal use only
|
static String[] |
split(String original,
String separator)
Provides a utility method breaks a given String to array of String according
to the given separator
|
static char[] |
toCharArray(String s)
toCharArray should return a new array always, however some devices might
suffer a bug that allows mutating a String (serious security hole in the JVM)
hence this method simulates the proper behavior
|
static void |
writeObject(Object o,
DataOutputStream out)
Writes an object to the given output stream
|
static void |
writeUTF(String s,
DataOutputStream d)
Writes a string with a null flag, this allows a String which may be null
|
public static void setIgnorCharsWhileEncoding(String s)
s
- set of characters to skip when encodingpublic static String getIgnorCharsWhileEncoding()
public static void copy(InputStream i, OutputStream o) throws IOException
i
- sourceo
- destinationIOException
public static void copy(InputStream i, OutputStream o, int bufferSize) throws IOException
i
- sourceo
- destinationbufferSize
- the size of the buffer, which should be a power of 2 large enoguhIOException
public static void cleanup(Object o)
o
- Connection, Stream or other closeable objectpublic static String readToString(InputStream i) throws IOException
i
- the input streamIOException
- thrown by the streampublic static String readToString(InputStream i, String encoding) throws IOException
i
- the input streamencoding
- the encoding of the streamIOException
- thrown by the streampublic static byte[] readInputStream(InputStream i) throws IOException
i
- the stream to convertIOException
public static void register(Externalizable e)
e
- the externalizable instancepublic static void register(String id, Class c)
id
- id of the externalizablec
- the class for the externalizablepublic static void writeObject(Object o, DataOutputStream out) throws IOException
o
- the object to write which can be nullout
- the destination output streamIOException
- thrown by the streampublic static boolean instanceofObjArray(Object o)
o
- object to testpublic static boolean instanceofByteArray(Object o)
o
- object to testpublic static boolean instanceofShortArray(Object o)
o
- object to testpublic static boolean instanceofLongArray(Object o)
o
- object to testpublic static boolean instanceofIntArray(Object o)
o
- object to testpublic static boolean instanceofFloatArray(Object o)
o
- object to testpublic static boolean instanceofDoubleArray(Object o)
o
- object to testpublic static Object readObject(DataInputStream input) throws IOException
input
- the source input streamIOException
- thrown by the streampublic static String encodeUrl(String str)
str
- none encoded stringpublic static char[] toCharArray(String s)
s
- a stringpublic static String decode(String s, String enc, boolean plusToSpace)
s
- the stringenc
- the encoding (defaults to UTF-8 if null)plusToSpace
- true if plus signs be converted to spacespublic static String encodeBody(String str)
str
- none encoded stringpublic static String encodeUrl(byte[] buf)
buf
- none encoded stringpublic static String encodeUrl(char[] buf)
buf
- none encoded stringpublic static String encodeBody(char[] buf)
buf
- none encoded stringpublic static String encodeBody(byte[] buf)
buf
- none encoded stringpublic static String relativeToAbsolute(String baseURL, String relativeURL)
baseURL
- a source URL whose properties should be used to construct the actual URLrelativeURL
- relative addresspublic static String getURLProtocol(String url)
url
- absolute URLpublic static String getURLHost(String url)
url
- absolute URLpublic static String getURLPath(String url)
url
- absolute URLpublic static String getURLBasePath(String url)
url
- absolute URLpublic static void writeUTF(String s, DataOutputStream d) throws IOException
s
- the string to writed
- the destination output streamIOException
public static String readUTF(DataInputStream d) throws IOException
d
- the streamIOException
public static void readFully(InputStream i, byte[] b) throws IOException
b
- the buffer into which the data is read.IOException
- the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public static final void readFully(InputStream i, byte[] b, int off, int len) throws IOException
b
- the buffer into which the data is read.off
- the start offset of the data.len
- the number of bytes to read.IOException
- the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public static int readAll(InputStream i, byte[] b) throws IOException
b
- the buffer into which the data is read.IOException
- the stream has been closed and the contained
input stream does not support reading after close, or
another I/O error occurs.public static String[] split(String original, String separator)
original
- the String to breakseparator
- the pattern to look in the original Stringpublic static void setImplementation(CodenameOneImplementation impl)
impl
- implementation instancepublic static void mergeArrays(Object[] arr1, Object[] arr2, Object[] destinationArray)
public static boolean downloadUrlToStorage(String url, String fileName, boolean showProgress)
url
- the URLfileName
- the storage file nameshowProgress
- whether to block the UI until download completes/failspublic static boolean downloadUrlToFile(String url, String fileName, boolean showProgress)
url
- the URLfileName
- the file nameshowProgress
- whether to block the UI until download completes/failspublic static void downloadUrlToStorageInBackground(String url, String fileName)
url
- the URLfileName
- the storage file namepublic static void downloadUrlToFileSystemInBackground(String url, String fileName)
url
- the URLfileName
- the file namepublic static void downloadUrlToStorageInBackground(String url, String fileName, ActionListener onCompletion)
url
- the URLfileName
- the storage file nameonCompletion
- invoked when download completespublic static void downloadUrlToFileSystemInBackground(String url, String fileName, ActionListener onCompletion)
url
- the URLfileName
- the file nameonCompletion
- invoked when download completes