Package java.io

Examples of java.io.CharArrayWriter


    } else if (list.isNil()) {
      return EBigString.EMPTY;

    } else {
      CharArrayWriter barr = new CharArrayWriter();

      EObject tail = list;
      while ((list = tail.testNonEmptyList()) != null) {

        EObject head = list.head();

        ESmall intval;
        if ((intval = head.testSmall()) == null) {
          throw ERT.badarg();
        }

        int byteValue = intval.value & 0xffff;
        if (intval.value != byteValue) {
          throw ERT.badarg();
        }

        barr.write(byteValue);
        tail = list.tail();
      }

      return new EBigString(barr.toCharArray(), 0);
    }
  }
View Full Code Here


    }
    BufferedReader in = new BufferedReader(new InputStreamReader(request
        .getInputStream(), charset));

    // Read the request
    CharArrayWriter data = new CharArrayWriter();
    char[] buf = new char[4096];
    int ret;
    while ((ret = in.read(buf, 0, 4096)) != -1) {
      data.write(buf, 0, ret);
    }

    JSONObject jsonReq = null;
    //String method = null;
    try {
      System.out.println(data.toString());
      String reqData = URLDecoder.decode(data.toString(), "UTF-8");
      jsonReq = new JSONObject(reqData);
      //method = jsonReq.getString("method");
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

      throw new HgAuthFailedException("Need username", null);
    }
    if (privateKey == null) {
      throw new HgAuthFailedException("Need private key", null);
    }
    CharArrayWriter a = new CharArrayWriter(2048);
    int r;
    try {
      while((r = privateKey.read()) != -1) {
        a.append((char) r);
      }
    } catch (IOException ex) {
      throw new HgAuthFailedException("Failed to read private key", ex);
    }
    try {
      boolean success = conn.authenticateWithPublicKey(username, a.toCharArray(), passphrase);
      if (!success) {
        throw authFailed(username);
      }
    } catch (IOException ex) {
      throw commFailed(ex);
View Full Code Here

     *  exception
     * @param throwable The <code>Throwable</code> error or exception
     */
    public void log(String msg, Throwable throwable) {

  CharArrayWriter buf = new CharArrayWriter();
  PrintWriter writer = new PrintWriter(buf);
  writer.print(msg);
  throwable.printStackTrace(writer);
  log(buf.toString());

    }
View Full Code Here

        }
        return buf.toString();
    }

    private String parseScriptText(String tx) {
        CharArrayWriter cw = new CharArrayWriter();
        int size = tx.length();
        int i = 0;
        while (i < size) {
            char ch = tx.charAt(i);
            if (i + 2 < size && ch == '%' && tx.charAt(i + 1) == '\\'
                    && tx.charAt(i + 2) == '>') {
                cw.write('%');
                cw.write('>');
                i += 3;
            } else {
                cw.write(ch);
                ++i;
            }
        }
        cw.close();
        return cw.toString();
    }
View Full Code Here

    private void parseTemplateText(Node parent) throws JasperException {

        if (!reader.hasMoreInput())
            return;

        CharArrayWriter ttext = new CharArrayWriter();
        // Output the first character
        int ch = reader.nextChar();
        if (ch == '\\') {
            reader.pushChar();
        } else {
            ttext.write(ch);
        }

        while (reader.hasMoreInput()) {
            ch = reader.nextChar();
            if (ch == '<') {
                reader.pushChar();
                break;
            } else if (ch == '$' || ch == '#') {
                if (!reader.hasMoreInput()) {
                    ttext.write(ch);
                    break;
                }
                if (reader.nextChar() == '{') {
                    reader.pushChar();
                    reader.pushChar();
                    break;
                }
                ttext.write(ch);
                reader.pushChar();
                continue;
            } else if (ch == '\\') {
                if (!reader.hasMoreInput()) {
                    ttext.write('\\');
                    break;
                }
                char next = (char) reader.peekChar();
                // Looking for \% or \$ or \#
                // TODO: only recognize \$ or \# if isELIgnored is false, but since
                // it can be set in a page directive, it cannot be determined
                // here. Argh! (which is the way it should be since we shouldn't
                // convolude multiple steps at once and create confusing parsers...)
                if (next == '%' || next == '$' || next == '#') {
                    ch = reader.nextChar();
                }
            }
            ttext.write(ch);
        }
        new Node.TemplateText(ttext.toString(), start, parent);
    }
View Full Code Here

        if (!reader.matches("/>")) {
            if (!reader.matches(">")) {
                err.jspError(start, "jsp.error.unterminated",
                        "&lt;jsp:text&gt;");
            }
            CharArrayWriter ttext = new CharArrayWriter();
            while (reader.hasMoreInput()) {
                int ch = reader.nextChar();
                if (ch == '<') {
                    // Check for <![CDATA[
                    if (!reader.matches("![CDATA[")) {
                        break;
                    }
                    start = reader.mark();
                    Mark stop = reader.skipUntil("]]>");
                    if (stop == null) {
                        err.jspError(start, "jsp.error.unterminated", "CDATA");
                    }
                    String text = reader.getText(start, stop);
                    ttext.write(text, 0, text.length());
                } else if (ch == '\\') {
                    if (!reader.hasMoreInput()) {
                        ttext.write('\\');
                        break;
                    }
                    ch = reader.nextChar();
                    if (ch != '$' && ch != '#') {
                        ttext.write('\\');
                    }
                    ttext.write(ch);
                } else if (ch == '$' || ch == '#') {
                    if (!reader.hasMoreInput()) {
                        ttext.write(ch);
                        break;
                    }
                    if (reader.nextChar() != '{') {
                        ttext.write(ch);
                        reader.pushChar();
                        continue;
                    }
                    // Create a template text node
                    new Node.TemplateText(ttext.toString(), start, parent);

                    // Mark and parse the EL expression and create its node:
                    start = reader.mark();
                    parseELExpression(parent, (char) ch);

                    start = reader.mark();
                    ttext = new CharArrayWriter();
                } else {
                    ttext.write(ch);
                }
            }

            new Node.TemplateText(ttext.toString(), start, parent);

            if (!reader.hasMoreInput()) {
                err.jspError(start, "jsp.error.unterminated",
                        "&lt;jsp:text&gt;");
            } else if (!reader.matchesETagWithoutLessThan("jsp:text")) {
View Full Code Here

        InternalValue[] values = data.getValues();
        if (values.length > 0) {
            final BLOBFileValue blob = (BLOBFileValue) values[0].internalValue();
            LazyReader reader = new LazyReader() {
                protected void initializeReader() throws IOException {
                    CharArrayWriter writer = new CharArrayWriter();

                    InputStream in;
                    try {
                        in = blob.getStream();
                    } catch (RepositoryException e) {
                        throw new IOException(e.getMessage());
                    }

                    try {
                        POIFSFileSystem fs = new POIFSFileSystem(in);
                        HSSFWorkbook workbook = new HSSFWorkbook(fs);

                        for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
                            HSSFSheet sheet = workbook.getSheetAt(i);

                            Iterator rows = sheet.rowIterator();
                            while (rows.hasNext()) {
                                HSSFRow row = (HSSFRow) rows.next();

                                Iterator cells = row.cellIterator();
                                while (cells.hasNext()) {
                                    HSSFCell cell = (HSSFCell) cells.next();
                                    switch (cell.getCellType()) {
                                    case HSSFCell.CELL_TYPE_NUMERIC:
                                        String num = Double.toString(cell.getNumericCellValue()).trim();
                                        if (num.length() > 0) {
                                            writer.write(num + " ");
                                        }
                                        break;
                                    case HSSFCell.CELL_TYPE_STRING:
                                        String text = cell.getStringCellValue().trim();
                                        if (text.length() > 0) {
                                            writer.write(text + " ");
                                        }
                                        break;
                                    }
                                }
                            }
                        }

                        delegate = new CharArrayReader(writer.toCharArray());
                    } finally {
                        in.close();
                    }
                }
            };
View Full Code Here

                        parser = new PDFParser(new BufferedInputStream(in));
                        parser.parse();

                        PDDocument document = parser.getPDDocument();
                        try {
                            CharArrayWriter writer = new CharArrayWriter();

                            PDFTextStripper stripper = new PDFTextStripper();
                            stripper.setLineSeparator("\n");
                            stripper.writeText(document, writer);

                            delegate = new CharArrayReader(writer.toCharArray());
                        } finally {
                            document.close();
                        }
                    } finally {
                        in.close();
View Full Code Here

  public String encode(final String s, final String charsetName)
  {
    boolean needToChange = false;
    StringBuilder out = new StringBuilder(s.length());
    Charset charset;
    CharArrayWriter charArrayWriter = new CharArrayWriter();

    Args.notNull(charsetName, "charsetName");

    try
    {
      charset = Charset.forName(charsetName);
    }
    catch (IllegalCharsetNameException e)
    {
      throw new RuntimeException(new UnsupportedEncodingException(charsetName));
    }
    catch (UnsupportedCharsetException e)
    {
      throw new RuntimeException(new UnsupportedEncodingException(charsetName));
    }

    boolean stopEncoding = false;
    for (int i = 0; i < s.length();)
    {
      int c = s.charAt(i);

      if ((stopEncoding == false) && (c == stopChar))
      {
        stopEncoding = true;
      }

      // System.out.println("Examining character: " + c);
      if ((stopEncoding == true) || dontNeedEncoding.get(c))
      {
        if (c == ' ')
        {
          c = '+';
          needToChange = true;
        }
        // System.out.println("Storing: " + c);
        out.append((char)c);
        i++;
      }
      else
      {
        // convert to external encoding before hex conversion
        do
        {
          charArrayWriter.write(c);
          /*
           * If this character represents the start of a Unicode surrogate pair, then pass
           * in two characters. It's not clear what should be done if a bytes reserved in
           * the surrogate pairs range occurs outside of a legal surrogate pair. For now,
           * just treat it as if it were any other character.
           */
          if ((c >= 0xD800) && (c <= 0xDBFF))
          {
            /*
             * System.out.println(Integer.toHexString(c) + " is high surrogate");
             */
            if ((i + 1) < s.length())
            {
              int d = s.charAt(i + 1);
              /*
               * System.out.println("\tExamining " + Integer.toHexString(d));
               */
              if ((d >= 0xDC00) && (d <= 0xDFFF))
              {
                /*
                 * System.out.println("\t" + Integer.toHexString(d) + " is low
                 * surrogate");
                 */
                charArrayWriter.write(d);
                i++;
              }
            }
          }
          i++;
        }
        while ((i < s.length()) && !dontNeedEncoding.get((c = s.charAt(i))));

        charArrayWriter.flush();
        String str = new String(charArrayWriter.toCharArray());
        byte[] ba;
        try
        {
          ba = str.getBytes(charset.name());
        }
        catch (UnsupportedEncodingException e)
        {
          throw new RuntimeException(e);
        }
        for (byte b : ba)
        {
          out.append('%');
          char ch = Character.forDigit((b >> 4) & 0xF, 16);
          // converting to use uppercase letter as part of
          // the hex value if ch is a letter.
          if (Character.isLetter(ch))
          {
            ch -= caseDiff;
          }
          out.append(ch);
          ch = Character.forDigit(b & 0xF, 16);
          if (Character.isLetter(ch))
          {
            ch -= caseDiff;
          }
          out.append(ch);
        }
        charArrayWriter.reset();
        needToChange = true;
      }
    }

    return (needToChange ? out.toString() : s);
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.