Example usage for java.io Writer write

List of usage examples for java.io Writer write

Introduction

In this page you can find the example usage for java.io Writer write.

Prototype

public void write(String str, int off, int len) throws IOException 

Source Link

Document

Writes a portion of a string.

Usage

From source file:Main.java

public static void encodeTextValue(char[] characters, int offset, int length, Writer writer)
        throws IOException {
    for (int i = offset; i < offset + length; i++) {
        char c = characters[i];
        switch (c) {
        case '<':
            writer.write(LT, 0, LT.length);
            break;
        case '>':
            writer.write(GT, 0, GT.length);
            break;
        case '&':
            writer.write(AMP, 0, AMP.length);
            break;
        default:/*from  www. jav  a 2 s .c om*/
            writer.write(c);
        }
    }
}

From source file:net.sf.keystore_explorer.utilities.io.CopyUtil.java

/**
 * Copy data from a reader to a writer and do not close I/O.
 *
 * @param reader/*from   ww  w .j  ava 2s.  c om*/
 *            Reader
 * @param writer
 *            Writer
 * @throws IOException
 *             If an I/O problem occurred
 */
public static void copy(Reader reader, Writer writer) throws IOException {
    char[] buffer = new char[2048];
    int i;
    while ((i = reader.read(buffer)) > 0) {
        writer.write(buffer, 0, i);
    }
}

From source file:com.scorpio4.util.io.StreamCopy.java

public static void copy(Reader input, Writer output, int buffer_size) throws IOException {
    char[] buffer = new char[buffer_size + 16];
    int n = 0;// w w  w.j  a va  2  s .  co  m
    while (-1 != (n = input.read(buffer))) {
        output.write(buffer, 0, n);
        output.flush();
    }
    output.flush();
}

From source file:Main.java

public static void encodeAttributeValue(char[] characters, int offset, int length, Writer writer)
        throws IOException {
    for (int i = offset; i < offset + length; i++) {
        char c = characters[i];
        switch (c) {
        case '<':
            writer.write(LT, 0, LT.length);
            break;
        case '>':
            writer.write(GT, 0, GT.length);
            break;
        case '&':
            writer.write(AMP, 0, AMP.length);
            break;
        case '\'':
            writer.write(APOS, 0, APOS.length);
            break;
        case '\"':
            writer.write(QUOT, 0, QUOT.length);
            break;
        default://w  ww  .java2  s  .  co  m
            writer.write(c);
        }
    }
}

From source file:Main.java

/**
 * Copies characters from a reader to a writer. When the reading is done,
 * the reader is closed./* w  ww .j  av  a2 s  .  c  om*/
 * 
 * @param reader
 *            The reader.
 * @param writer
 *            The writer.
 * @throws IOException
 */
public static void copy(Reader reader, java.io.Writer writer) throws IOException {
    int charsRead;
    char[] buffer = new char[2048];

    while ((charsRead = reader.read(buffer)) > 0) {
        writer.write(buffer, 0, charsRead);
    }

    writer.flush();
    reader.close();
}

From source file:com.ln.methods.Getcalendar.java

public static void Main() {
    //TODO store file locally and check if file changed == redownload
    try {/*from w w  w.  j  a va 2 s.  c  o  m*/

        //Get source
        // System.setProperty("http.agent", "lnrev2");
        URL calendar = new URL(Calendarurl);
        HttpURLConnection getsource = (HttpURLConnection) calendar.openConnection();
        InputStream in = new BufferedInputStream(getsource.getInputStream());
        //Write source
        Writer sw = new StringWriter();
        char[] b = new char[1024];
        Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
        int n;
        while ((n = reader.read(b)) != -1) {
            sw.write(b, 0, n);
        }
        //Source == String && Send source for parsing
        Parser.source = sw.toString();
        Betaparser.source = sw.toString();

        //String lol = sw.toString();
        //lol = StringUtils.substringBetween(lol, "<month year=\"2012\" num=\"2\">", "</month>");
        //Parser.parse();

        Betaparser.parse();

    } catch (MalformedURLException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, e.getStackTrace(), "Error", JOptionPane.WARNING_MESSAGE);
    } catch (IOException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, e.getStackTrace(), "Error", JOptionPane.WARNING_MESSAGE);
    }
}

From source file:Main.java

public static int copy(Reader input, Writer output) throws IOException {
    char[] buffer = new char[10 * 1024];
    int count = 0;
    int n = 0;/*from   ww w . ja v a2s. c  om*/
    while (-1 != (n = input.read(buffer))) {
        output.write(buffer, 0, n);
        count += n;
    }
    return count;
}

From source file:Main.java

private static String convertStreamToString(InputStream is) {
    Writer writer = new StringWriter();
    char[] buffer = new char[2048];
    try {/*  w w  w  .jav  a  2s.c  om*/
        Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        int len;
        while ((len = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, len);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return writer.toString();
}

From source file:Main.java

public static String getDefaultCurrencies(InputStream is) {

    Writer writer = new StringWriter();
    char[] buffer = new char[1024];
    try {/*from  w  w  w  .  j a va  2s.  co  m*/
        Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        int n;
        while ((n = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, n);
        }
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "loadCurrencies " + "Encoding error");
    } catch (IOException e) {
        Log.e(TAG, "loadCurrencies " + "IOException");
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            Log.e(TAG, "loadCurrencies " + "IOException - close");
        }
    }
    return writer.toString();
}

From source file:Main.java

static public String convertStreamToString(InputStream is) throws IOException {
    if (is != null) {
        Writer writer = new StringWriter();
        char[] buffer = new char[1024];
        try {/* ww  w  .j  a  va 2 s  .  com*/
            Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            int n;
            while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
            }
        } finally {
            is.close();
        }
        return writer.toString();
    } else {
        return "";
    }
}