Package java.io

Examples of java.io.CharArrayWriter


                try { bout.close();} catch (IOException ignored) {}
                try { inp.reset();} catch (IOException ignored) {}
                ret = new SAXSource(new InputSource(new ByteArrayInputStream(bout.toByteArray())));
            } else if(ssrc.getInputSource().getCharacterStream() != null) {
                Reader rdr = ssrc.getInputSource().getCharacterStream();
                CharArrayWriter caw = new CharArrayWriter();
                try {
                    int c;
                    while((c = rdr.read()) != -1) {
                        caw.append((char)c);
                    }
                } catch (IOException ignored) {
                }
                caw.close();
                try{ rdr.reset();} catch(IOException ignored) {}
                ret = new SAXSource(new InputSource(new CharArrayReader(caw.toCharArray())));
            } else {
                ret = new SAXSource();
            }
        } else if(src instanceof StreamSource) {
            StreamSource ssrc = (StreamSource)src;
            if(ssrc.getInputStream() != null) {
                InputStream inp = ssrc.getInputStream();
                ByteArrayOutputStream bout = new ByteArrayOutputStream();
                int b;
                try {
                    while((b = inp.read()) != -1) {
                        bout.write(b);
                    }
                } catch (IOException ignored) {
                }
                try { bout.close();} catch (IOException ignored) {}
                try { inp.reset();} catch (IOException ignored) {}
                ret = new StreamSource(new ByteArrayInputStream(bout.toByteArray()));
            } else if(ssrc.getReader() != null) {
                Reader rdr = ssrc.getReader();
                CharArrayWriter caw = new CharArrayWriter();
                try {
                    int c;
                    while((c = rdr.read()) != -1) {
                        caw.append((char)c);
                    }
                } catch (IOException ignored) {
                }
                caw.close();
                try{ rdr.reset();} catch(IOException ignored) {}
                ret = new StreamSource(new CharArrayReader(caw.toCharArray()));
            } else {
                ret = new StreamSource();
            }
        }
       
View Full Code Here


                try { bout.close();} catch (IOException ignored) {}
                try { inp.reset();} catch (IOException ignored) {}
                ret = new SAXSource(new InputSource(new ByteArrayInputStream(bout.toByteArray())));
            } else if(ssrc.getInputSource().getCharacterStream() != null) {
                Reader rdr = ssrc.getInputSource().getCharacterStream();
                CharArrayWriter caw = new CharArrayWriter();
                try {
                    int c;
                    while((c = rdr.read()) != -1) {
                        caw.append((char)c);
                    }
                } catch (IOException ignored) {
                }
                caw.close();
                try{ rdr.reset();} catch(IOException ignored) {}
                ret = new SAXSource(new InputSource(new CharArrayReader(caw.toCharArray())));
            } else {
                ret = new SAXSource();
            }
        } else if(src instanceof StreamSource) {
            StreamSource ssrc = (StreamSource)src;
            if(ssrc.getInputStream() != null) {
                InputStream inp = ssrc.getInputStream();
                ByteArrayOutputStream bout = new ByteArrayOutputStream();
                int b;
                try {
                    while((b = inp.read()) != -1) {
                        bout.write(b);
                    }
                } catch (IOException ignored) {
                }
                try { bout.close();} catch (IOException ignored) {}
                try { inp.reset();} catch (IOException ignored) {}
                ret = new StreamSource(new ByteArrayInputStream(bout.toByteArray()));
            } else if(ssrc.getReader() != null) {
                Reader rdr = ssrc.getReader();
                CharArrayWriter caw = new CharArrayWriter();
                try {
                    int c;
                    while((c = rdr.read()) != -1) {
                        caw.append((char)c);
                    }
                } catch (IOException ignored) {
                }
                caw.close();
                try{ rdr.reset();} catch(IOException ignored) {}
                ret = new StreamSource(new CharArrayReader(caw.toCharArray()));
            } else {
                ret = new StreamSource();
            }
        }
       
View Full Code Here

    }
  }

  public void testEncodeArrayLineBreak2() {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      char[] source = stringLineBreak.toCharArray();
      HTMLEncoder.encode(source, 0, source.length, false, writer);
      assertEquals(stringLineBreakEncoded2.toCharArray(), writer.toCharArray());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

    }
  }

  public void testEncodeArrayLineBreak2WrongIndex() {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      char[] source = stringLineBreak.toCharArray();
      HTMLEncoder.encode(source, 0, source.length + 5, false, writer);
      assertEquals(stringLineBreakEncoded2.toCharArray(), writer.toCharArray());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

    }
  }

  public void testEncodeArrayLineBreakPartial() {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      char[] source = stringLineBreak.toCharArray();
      HTMLEncoder.encode(source, 4, source.length - 5, writer);
      char[] expected = stringLineBreakEncoded2Partial.toCharArray();
      assertEquals(expected, writer.toCharArray());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

    assertEquals("", encodedStr);
  }

  public void testEncodeArrayNoSpecialChars() {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      char[] source = stringNoSpecialChars.toCharArray();
      HTMLEncoder.encode(source, 0, source.length, writer);
      assertEquals(stringNoSpecialCharsEncoded.toCharArray(), writer.toCharArray());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

    }
  }

  public void testEncodeArrayNoSpecialCharsPartial() {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      char[] source = stringNoSpecialChars.toCharArray();
      HTMLEncoder.encode(source, 3, source.length - 5, writer);
      assertEquals(stringNoSpecialCharsEncodedPartial.toCharArray(), writer.toCharArray());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

    }
  }

  public void testEncodeArraySpecialChars1() {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      char[] source = stringSpecialChars1.toCharArray();
      HTMLEncoder.encode(source, 0, source.length, writer);
      assertEquals(stringSpecialChars1Encoded.toCharArray(), writer.toCharArray());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

    }
  }

  public void testEncodeArraySpecialChars2() {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      char[] source = stringSpecialChars2.toCharArray();
      HTMLEncoder.encode(source, 0, source.length, writer);
      assertEquals(stringSpecialChars2Encoded.toCharArray(), writer.toCharArray());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

    }
  }

  public void testEncodeArrayEmpty() {
    try {
      CharArrayWriter writer = new CharArrayWriter();
      HTMLEncoder.encode(new char[]{}, 0, 1, writer);
      assertEquals(new char[]{}, writer.toCharArray());
    } catch (IOException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

TOP

Related Classes of java.io.CharArrayWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.