FileDocCategorySizeDatePackage
IOUtil.javaAPI DocAndroid 1.5 API5603Wed May 06 22:42:02 BST 2009android.core

IOUtil

public final class IOUtil extends Object

Fields Summary
Constructors Summary
private IOUtil()

    
Methods Summary
public static java.lang.StringmarkRead(java.io.InputStream a, int x, int y)
reads characters from a InputStream, skips back y characters and continues reading from that new position up to the end.

param
a the InputStream.
param
x the position of the mark. the marks position is x+y
param
y the number of characters to jump back after the position x+y was reached.
return
the string.
throws
IOException

        int m = 0;
        int r;
        StringBuilder builder = new StringBuilder();
        do {
            m++;
            r = a.read();
            if (m == x)
                a.mark((x + y));
            if (m == (x + y))
                a.reset();

            if (r != -1)
                builder.append((char) r);
        } while (r != -1);
        return builder.toString();
    
public static java.lang.StringmarkRead(java.io.Reader a, int x, int y)
reads characters from a reader, skips back y characters and continues reading from that new position up to the end.

param
a the reader.
param
x the position of the mark. the marks position is x+y
param
y the number of characters to jump back after the position x+y was reached.
return
the string.
throws
IOException

        int m = 0;
        int r;
        StringBuilder builder = new StringBuilder();
        do {
            m++;
            r = a.read();
            if (m == x)
                a.mark((x + y));
            if (m == (x + y))
                a.reset();

            if (r != -1)
                builder.append((char) r);
        } while (r != -1);
        return builder.toString();
    
public static java.lang.Stringread(java.io.InputStream a)
returns the content of an InputStream as a String.

param
a the input stream.
return
the string
throws
java.io.IOException

        int r;
        StringBuilder builder = new StringBuilder();
        do {
            r = a.read();
            if (r != -1)
                builder.append((char) r);
        } while (r != -1);
        return builder.toString();
    
public static java.lang.Stringread(java.io.Reader a)
reads characters from a reader and returns them as a string.

param
a the reader.
return
the string.
throws
IOException

        int r;
        StringBuilder builder = new StringBuilder();
        do {
            r = a.read();
            if (r != -1)
                builder.append((char) r);
        } while (r != -1);
        return builder.toString();
    
public static java.lang.Stringread(java.io.InputStream a, int x)
returns the content of an InputStream as a String. It reads x characters.

param
a the input stream.
param
x number of characters to read.
return
the string
throws
IOException

        byte[] b = new byte[x];
        int len = a.read(b, 0, x);
        if (len < 0) {
            return "";
        }
        return new String(b, 0, len);
    
public static java.lang.Stringread(java.io.Reader a, int x)
reads a number of characters from a reader and returns them as a string.

param
a the reader.
param
x the number of characters to read.
return
the string.
throws
IOException

        char[] b = new char[x];
        int len = a.read(b, 0, x);
        if (len < 0) {
            return "";
        }
        return new String(b, 0, len);
    
public static java.lang.StringskipRead(java.io.InputStream a)
returns the content of the input stream as a String. It only appends every second character.

param
a the input stream.
return
the string created from every second character of the input stream.
throws
IOException

        int r;
        StringBuilder builder = new StringBuilder();
        do {
            a.skip(1);
            r = a.read();
            if (r != -1)
                builder.append((char) r);
        } while (r != -1);
        return builder.toString();
    
public static java.lang.StringskipRead(java.io.Reader a)
reads every second characters from a reader and returns them as a string.

param
a the reader.
return
the string.
throws
IOException

        int r;
        StringBuilder builder = new StringBuilder();
        do {
            a.skip(1);
            r = a.read();
            if (r != -1)
                builder.append((char) r);
        } while (r != -1);
        return builder.toString();