Package com.caucho.vfs

Examples of com.caucho.vfs.ByteToChar


  }

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

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

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

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


   */
  private static String normalizeUriEscape(byte []rawUri, int i, int len,
                                           String encoding)
    throws IOException
  {
    ByteToChar converter = allocateConverter();
    // 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);
      }

      String result = converter.getConvertedString();
     
      freeConverter(converter);
     
      return result;
    } catch (Exception e) {
View Full Code Here

      return -1;
  }
 
  private static ByteToChar allocateConverter()
  {
    ByteToChar converter = _freeConverters.allocate();
   
    if (converter == null)
      converter = ByteToChar.create();
    else
      converter.clear();
   
    return converter;
  }
View Full Code Here

                               boolean isTop)
    throws IOException
  {
    CharCursor is = new StringCharCursor(query);

    ByteToChar converter = _converter;
    try {
      converter.setEncoding(javaEncoding);
    } catch (UnsupportedEncodingException e) {
      log.log(Level.FINE, e.toString(), e);
    }

    int ch = is.current();
    while (ch != CharacterIterator.DONE) {
      for (; Character.isWhitespace((char) ch) || ch == '&'; ch = is.next()) {
      }

      converter.clear();
      for (; ch != CharacterIterator.DONE && ch != '=' && ch != '&'; ch = is.next())
        readChar(converter, is, ch, isTop);

      String key = converter.getConvertedString();

      converter.clear();
      if (ch == '=')
        ch = is.next();
      for (; ch != CharacterIterator.DONE && ch != '&'; ch = is.next())
        readChar(converter, is, ch, isTop);
     
      String value = converter.getConvertedString();

      if (log.isLoggable(Level.FINE))
        log.fine("query: " + key + "=" + value);
     
      String []oldValue = table.get(key);
View Full Code Here

   */
  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

                               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 && isSeparator(querySeparatorMap, ch = str.charAt(i));
             i++) {
        }
     
        for (; i < len && (ch = str.charAt(i)) != '='
             && ! isSeparator(querySeparatorMap, ch); i++) {
          i = addQueryChar(byteToChar, str, len, i, ch);
        }

        String key = byteToChar.getConvertedString();

        byteToChar.clear();

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

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

        if (isRef) {
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

      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

             boolean isTop)
    throws IOException
  {
    CharCursor is = new StringCharCursor(query);

    ByteToChar converter = _converter;
    try {
      converter.setEncoding(javaEncoding);
    } catch (UnsupportedEncodingException e) {
      log.log(Level.FINE, e.toString(), e);
    }

    int ch = is.current();
    while (ch != CharacterIterator.DONE) {
      for (; Character.isWhitespace((char) ch) || ch == '&'; ch = is.next()) {
      }

      converter.clear();
      for (; ch != CharacterIterator.DONE && ch != '=' && ch != '&'; ch = is.next())
        readChar(converter, is, ch, isTop);

      String key = converter.getConvertedString();

      converter.clear();
      if (ch == '=')
        ch = is.next();
      for (; ch != CharacterIterator.DONE && ch != '&'; ch = is.next())
        readChar(converter, is, ch, isTop);
     
      String value = converter.getConvertedString();

      if (log.isLoggable(Level.FINE))
        log.fine("query: " + key + "=" + value);
     
      String []oldValue = table.get(key);
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.