|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sk.baka.ambient.commons.IOUtils
public final class IOUtils
Contains IO and HTTP utility methods.
Nested Class Summary | |
---|---|
static class |
IOUtils.HttpRequest
The http request |
Method Summary | |
---|---|
static void |
cat(Reader r)
Cat given reader to log. |
static void |
copy(InputStream in,
OutputStream out,
int bufferSize)
Copies input stream to the output stream. |
static String |
encodeURL(String url)
Encodes given URL as per URLEncoder.encode(String, String) . |
static String |
formatIP(int address)
Formats IP address contained in an integer and returns it as a string. |
static String |
getExt(String name)
Returns the extension of the file, starting with dot character. |
static IOUtils.HttpRequest |
parseRequest(String request)
Parses given HTTP request. |
static void |
parseXML(InputStream in,
ContentHandler handler)
Parses XML readable from given stream. |
static String |
readLine(InputStream in)
Reads a line from given stream. |
static void |
readRequest(InputStream in)
Reads the request until an empty string is encountered. |
static String |
removeTrailingSlash(String name)
Removes trailing slash from given file name. |
static String |
stripExt(String name)
Strips extension from given name. |
static void |
writeHttpResponse(byte httpVer,
int httpCode,
boolean keepAlive,
long size,
String resultMime,
OutputStream out)
Writes HTTP response. |
static void |
writeLine(OutputStream out)
Writes an empty line to given stream. |
static void |
writeLine(String string,
OutputStream out)
Writes a line to given stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static String encodeURL(String url)
URLEncoder.encode(String, String)
. Uses
UTF-8 encoding. Spaces are correctly represented as %20
.
url
- the URL to encode
public static void parseXML(InputStream in, ContentHandler handler) throws IOException, SAXException
in
- the stream, always closed.handler
- handles XML events.
SAXException
- if parsing fails
IOException
- if i/o error occurspublic static String readLine(InputStream in) throws IOException
in
- the stream to read from. This should be an
BufferedInputStream
implementation for performance
reasons.
null
on end-of-stream.
IOException
- if i/o error occurs.public static void writeLine(String string, OutputStream out) throws IOException
string
- the string to write. It must consist of ASCII characters only.out
- the stream to write to.
IOException
- if i/o error occurs.public static void writeLine(OutputStream out) throws IOException
out
- the stream to write to.
IOException
- if i/o error occurs.public static String stripExt(String name)
name
- the name to strip extension from
public static void copy(InputStream in, OutputStream out, int bufferSize) throws IOException
in
- the input stream. Always closed.out
- the output stream. Always closed.bufferSize
- the buffer size in bytes
IOException
- thrown when i/o error occurs or when interrupted.public static String removeTrailingSlash(String name)
name
- the file name.
public static void readRequest(InputStream in) throws IOException
in
- the stream to read from.
IOException
- if i/o error occurs.public static IOUtils.HttpRequest parseRequest(String request) throws ServerHttpException
request
- the request
null
if the request is malformed.
ServerHttpException
- on HTTP error.public static void writeHttpResponse(byte httpVer, int httpCode, boolean keepAlive, long size, String resultMime, OutputStream out) throws IOException
httpVer
- the HTTP version, 0 or 1.httpCode
- the HTTP code.keepAlive
- if true
then "keep-alive" is written. If
false
then "close" is written.size
- the size of the content. -1 if not known.resultMime
- response MIME type.out
- write the response here.
IOException
- if i/o error occurspublic static void cat(Reader r)
r
- the reader to cat.public static String formatIP(int address)
address
- the IP to decode
public static String getExt(String name)
name
- the file name to get the extension from.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |