Package com.caucho.vfs

Examples of com.caucho.vfs.ByteToChar


   */
  void parsePostData(HashMapImpl<String,String[]> table, InputStream is,
         String javaEncoding)
    throws IOException
  {
    ByteToChar converter = _converter;
    try {
      converter.setEncoding(javaEncoding);
    } catch (UnsupportedEncodingException e) {
      log.log(Level.FINE, e.toString(), e);
    }

    int ch = is.read();
    while (ch >= 0) {
      for (; Character.isWhitespace((char) ch) || ch == '&'; ch = is.read()) {
      }

      converter.clear();
      for (;
           ch >= 0 && ch != '=' && ch != '&' &&
             ! Character.isWhitespace((char) ch);
           ch = is.read()) {
        readChar(converter, is, ch);
      }

      String key = converter.getConvertedString();

      for (; Character.isWhitespace((char) ch); ch = is.read()) {
      }
     
      converter.clear();
      if (ch == '=') {
        ch = is.read();
  for (; Character.isWhitespace((char) ch); ch = is.read()) {
  }
      }
     
      for (; ch >= 0 && ch != '&'; ch = is.read())
        readChar(converter, is, ch);
     
      String value = converter.getConvertedString();

      /* Could show passwords
      if (log.isLoggable(Level.FINE))
        log.fine("post: " + key + "=" + value);
      */
 
View Full Code Here


  }

  private String byteToChar(byte []buffer, int offset, int length,
                            String encoding)
  {
    ByteToChar converter = ByteToChar.create();
    // XXX: make this configurable

    if (encoding == null)
      encoding = "utf-8";

    try {
      converter.setEncoding(encoding);
    } catch (UnsupportedEncodingException e) {
      log.log(Level.FINE, e.toString(), e);
    }

    try {
      for (; length > 0; length--)
        converter.addByte(buffer[offset++]);
     
      return converter.getConvertedString();
    } catch (IOException e) {
      return "unknown";
    }
  }
View Full Code Here

   */
  private static String normalizeUriEscape(byte []rawUri, int i, int len,
                                           String encoding)
    throws IOException
  {
    ByteToChar converter = ByteToChar.create();
    // XXX: make this configurable

    if (encoding == null)
      encoding = "utf-8";

    try {
      converter.setEncoding(encoding);
    } catch (UnsupportedEncodingException e) {
      log.log(Level.FINE, e.toString(), e);
    }

    try {
      while (i < len) {
        int ch = rawUri[i++] & 0xff;

        if (ch == '%')
          i = scanUriEscape(converter, rawUri, i, len);
        else
          converter.addByte(ch);
      }

      return converter.getConvertedString();
    } catch (Exception e) {
      throw new BadRequestException(L.l("The URL contains escaped bytes unsupported by the {0} encoding.", encoding));
    }
  }
View Full Code Here

   */
  private void scanError(InputStream is, LineMap lineMap, CharBuffer errors)
    throws IOException
  {
    int ch = is.read();
    ByteToChar sourceLine = ByteToChar.create();
    sourceLine.setEncoding(System.getProperty("file.encoding"));
    filename = "filename";

    buf.clear();
    while (ch >= 0) {
      int colOffset = 0;
      for (; ch >= 0 && (ch == ' ' || ch == '\t'); ch = is.read())
  colOffset++;

      int line = 0;
      for (; ch >= 0 && ch >= '0' && ch <= '9'; ch = is.read()) {
  line = 10 * line + ch - '0';
  colOffset++;
      }

      if (ch < 0)
  return;
      else if (colOffset == 0 && ! Character.isWhitespace((char) ch)) {
  ch = scanUnknownLine(is, ch, errors);
      }
      else if (ch != '.') {
  ch = skipToNewline(is, ch);
  continue;
      }

      sourceLine.clear();
      for (ch = is.read(); ch >= 0 && ch != '\n'; ch = is.read())
  sourceLine.addByte(ch);
      sourceLine.addChar('\n');

      int column = 0;
      for (ch = is.read(); ch >= 0 && ch != '\n'; ch = is.read()) {
  if (ch == '^')
    break;
  else if (ch == ' ')
    column++;
  else if (ch == '\t')
    column = ((column + 8) / 8) * 8;
      }
      for (int i = colOffset + 1; i < column; i++)
  sourceLine.addChar(' ');
      sourceLine.addChar('^');
      sourceLine.addChar('\n');

      ch = skipToNewline(is, ch);
      if (ch != '*')
  continue;

      buf.clear();
      for (; ch >= 0 && ch != ':' && ch != '\n'; ch = is.read()) {
      }

      if (ch != ':') {
  ch = skipToNewline(is, ch);
  continue;
      }

      for (ch = is.read();
     ch >= 0 && (ch == ' ' || ch == ' ');
     ch = is.read()) {
      }

      for (; ch >= 0 && ch != '\n'; ch = is.read())
  buf.addByte(ch);

      String message = buf.getConvertedString();

      if (lineMap != null)
  errors.append(lineMap.convertError(filename, line, 0, message));
      else
  errors.append(filename + ":" + line + ": " + message);
      errors.append('\n');
      errors.append(sourceLine.getConvertedString());
    }
  }
View Full Code Here

                               boolean isRef,
                               String encoding,
                               boolean isMagicQuotes)
  {
    try {
      ByteToChar byteToChar = env.getByteToChar();
     
      if (encoding != null)
        byteToChar.setEncoding(encoding);
     
      int len = str.length();

      for (int i = 0; i < len; i++) {
        int ch = 0;
        byteToChar.clear();

        for (; i < len && (ch = str.charAt(i)) == '&'; i++) {
        }
     
        for (; i < len && (ch = str.charAt(i)) != '=' && ch != '&'; i++) {
          i = addQueryChar(byteToChar, str, len, i, ch);
        }

        String key = byteToChar.getConvertedString();

        byteToChar.clear();

        String value;
        if (ch == '=') {
          for (i++; i < len && (ch = str.charAt(i)) != '&'; i++) {
            i = addQueryChar(byteToChar, str, len, i, ch);
          }

          value = byteToChar.getConvertedString();
        }
        else
          value = "";

        if (isRef) {
View Full Code Here

  {
    try {
      if (source == null || source.length() == 0)
        return BooleanValue.FALSE;

      ByteToChar byteToChar = env.getByteToChar();

      int length = source.length();

      int i = 0;
      while (i < length) {
        int ch1 = source.charAt(i++);

        if (ch1 == 0x60 || ch1 == 0x20)
          break;
        else if (ch1 < 0x20 || 0x5f < ch1)
          continue;

        int sublen = ch1 - 0x20;

        while (sublen > 0) {
          int code;

          code = ((source.charAt(i++) - 0x20) & 0x3f) << 18;
          code += ((source.charAt(i++) - 0x20) & 0x3f) << 12;
          code += ((source.charAt(i++) - 0x20) & 0x3f) << 6;
          code += ((source.charAt(i++) - 0x20) & 0x3f);

          byteToChar.addByte(code >> 16);

          if (sublen > 1)
            byteToChar.addByte(code >> 8);

          if (sublen > 2)
            byteToChar.addByte(code);

          sublen -= 3;
        }
      }

      return env.createStringOld(byteToChar.getConvertedString());
    } catch (IOException e) {
      throw new QuercusModuleException(e);
    }
  }
View Full Code Here

      int length = source.length();

      if (length == 0)
        return BooleanValue.FALSE;

      ByteToChar byteToChar = env.getByteToChar();

      int i = 0;
      while (i < length) {
        int ch1 = source.charAt(i++);

        if (ch1 == 0x60 || ch1 == 0x20)
          break;
        else if (ch1 < 0x20 || 0x5f < ch1)
          continue;

        int sublen = ch1 - 0x20;

        while (sublen > 0) {
          int code;

          code = ((source.charAt(i++) - 0x20) & 0x3f) << 18;
          code += ((source.charAt(i++) - 0x20) & 0x3f) << 12;
          code += ((source.charAt(i++) - 0x20) & 0x3f) << 6;
          code += ((source.charAt(i++) - 0x20) & 0x3f);

          byteToChar.addByte(code >> 16);

          if (sublen > 1)
            byteToChar.addByte(code >> 8);

          if (sublen > 2)
            byteToChar.addByte(code);

          sublen -= 3;
        }
      }

      return env.createString(byteToChar.getConvertedString());
    } catch (IOException e) {
      throw new QuercusModuleException(e);
    }
  }
View Full Code Here

                               String encoding,
                               boolean isMagicQuotes,
                               int []querySeparatorMap)
  {
    try {
      ByteToChar byteToChar = env.getByteToChar();
     
      if (encoding != null)
        byteToChar.setEncoding(encoding);
     
      int len = str.length();

      for (int i = 0; i < len; i++) {
        int ch = 0;
        byteToChar.clear();

        for (; i < len && querySeparatorMap[ch = str.charAt(i)] > 0; i++) {
        }
     
        for (; i < len && (ch = str.charAt(i)) != '='
             && querySeparatorMap[ch] == 0; i++) {
          i = addQueryChar(byteToChar, str, len, i, ch);
        }

        String key = byteToChar.getConvertedString();

        byteToChar.clear();

        String value;
        if (ch == '=') {
          for (i++; i < len
               && querySeparatorMap[ch = str.charAt(i)] == 0; i++) {
            i = addQueryChar(byteToChar, str, len, i, ch);
          }

          value = byteToChar.getConvertedString();
        }
        else
          value = "";

        if (isRef) {
View Full Code Here

   */
  private void scanError(InputStream is, LineMap lineMap, CharBuffer errors)
    throws IOException
  {
    int ch = is.read();
    ByteToChar sourceLine = ByteToChar.create();
    sourceLine.setEncoding(System.getProperty("file.encoding"));
    filename = "filename";

    buf.clear();
    while (ch >= 0) {
      int colOffset = 0;
      for (; ch >= 0 && (ch == ' ' || ch == '\t'); ch = is.read())
        colOffset++;

      int line = 0;
      for (; ch >= 0 && ch >= '0' && ch <= '9'; ch = is.read()) {
        line = 10 * line + ch - '0';
        colOffset++;
      }

      if (ch < 0)
        return;
      else if (colOffset == 0 && ! Character.isWhitespace((char) ch)) {
        ch = scanUnknownLine(is, ch, errors);
      }
      else if (ch != '.') {
        ch = skipToNewline(is, ch);
        continue;
      }

      sourceLine.clear();
      for (ch = is.read(); ch >= 0 && ch != '\n'; ch = is.read())
        sourceLine.addByte(ch);
      sourceLine.addChar('\n');

      int column = 0;
      for (ch = is.read(); ch >= 0 && ch != '\n'; ch = is.read()) {
        if (ch == '^')
          break;
        else if (ch == ' ')
          column++;
        else if (ch == '\t')
          column = ((column + 8) / 8) * 8;
      }
      for (int i = colOffset + 1; i < column; i++)
        sourceLine.addChar(' ');
      sourceLine.addChar('^');
      sourceLine.addChar('\n');

      ch = skipToNewline(is, ch);
      if (ch != '*')
        continue;

      buf.clear();
      for (; ch >= 0 && ch != ':' && ch != '\n'; ch = is.read()) {
      }

      if (ch != ':') {
        ch = skipToNewline(is, ch);
        continue;
      }

      for (ch = is.read();
           ch >= 0 && (ch == ' ' || ch == ' ');
           ch = is.read()) {
      }

      for (; ch >= 0 && ch != '\n'; ch = is.read())
        buf.addByte(ch);

      String message = buf.getConvertedString();

      if (lineMap != null)
        errors.append(lineMap.convertError(filename, line, 0, message));
      else
        errors.append(filename + ":" + line + ": " + message);
      errors.append('\n');
      errors.append(sourceLine.getConvertedString());
    }
  }
View Full Code Here

TOP

Related Classes of com.caucho.vfs.ByteToChar

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.