Package java.io

Examples of java.io.UnsupportedEncodingException


   * @return decoded string or original if no decoding required
   * @throws UnsupportedEncodingException
   */
  public static String decode(String s, String enc) throws UnsupportedEncodingException {
    if (enc == null || enc.length() == 0) {
      throw new UnsupportedEncodingException("decode: no source char encoding provided.");
    }
    if (s == null)
      return null;
    boolean decoded = false;
    int l = s.length();
View Full Code Here


      {
        // check the supplied encoding ...
        // only Cp- encodings are supported ...
        if (EncodingRegistry.getInstance().isSupportedEncoding(cp) == false)
        {
          throw new UnsupportedEncodingException("The encoding " + cp + "is not valid");
        }

        final String encodingName = cp.substring(2);
        try
        {
          int i;
          if (Character.isDigit(encodingName.charAt(encodingName.length() - 1)) == false)
          {
            i = Integer.parseInt(encodingName.substring(0, encodingName.length() - 1));
            i += 10000;
          }
          else
          {
            i = Integer.parseInt(encodingName);
          }
          final byte[] retval = new byte[2];
          retval[0] = (byte) (i >> 8);
          retval[1] = (byte) (i & 0xff);
          return retval;
        }
        catch (Exception e)
        {
          throw new UnsupportedEncodingException("The encoding " + cp + "is not valid");
        }
      }
      throw new UnsupportedEncodingException("The encoding " + cp + " is no codepage encoding");
    }
View Full Code Here

      throws SecurityException, java.io.UnsupportedEncodingException {
  checkAccess();
  if (encoding != null) {
      try {
          if(!java.nio.charset.Charset.isSupported(encoding)) {
              throw new UnsupportedEncodingException(encoding);
          }    
      } catch (java.nio.charset.IllegalCharsetNameException e) {
          throw new UnsupportedEncodingException(encoding);
      }
  }
  this.encoding = encoding;
    }
View Full Code Here

                    eInfo = new EncodingInfo(EncodingMap.getJava2IANAMapping(encoding), encoding, DEFAULT_LAST_PRINTABLE);
                }
                _encodings.put(encoding, eInfo);
                return eInfo;
            } else {
                throw new UnsupportedEncodingException(encoding);
            }
        }
        if ((eInfo = (EncodingInfo)_encodings.get(jName)) != null)
            return eInfo;
        // have to create one...
View Full Code Here

    Charset cs = lookupCharset(csn);
    if (cs != null)
        sd = new StringDecoder(cs, csn);
      } catch (IllegalCharsetNameException x) {}
            if (sd == null)
                throw new UnsupportedEncodingException(csn);
      set(decoder, sd);
  }
  return sd.decode(ba, off, len);
    }
View Full Code Here

    Charset cs = lookupCharset(csn);
    if (cs != null)
        se = new StringEncoder(cs, csn);
      } catch (IllegalCharsetNameException x) {}
      if (se == null)
                throw new UnsupportedEncodingException (csn);
      set(encoder, se);
  }
  return se.encode(ca, off, len);
    }
View Full Code Here

      throw new NullPointerException("charsetName");

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

  for (int i = 0; i < s.length();) {
      int c = (int) s.charAt(i);
      //System.out.println("Examining character: " + c);
View Full Code Here

                                                      ((bytes[byteIndex++] & THREE_BYTE_MASK2) << THREE_BYTE_SHIFT2) |
                                                      ((bytes[byteIndex++] & THREE_BYTE_MASK3)                     ));
            }
            catch (ArrayIndexOutOfBoundsException e)
            {
                throw new UnsupportedEncodingException("Missing UTF-8 bytes after initial byte [0x"+Integer.toHexString(b)+"] in string ["+new String(chars, 0, charIndex)+"]");
            }
        }

        return new String(chars, 0, charIndex);
    }
View Full Code Here

            {
                is = new QInputStream(bis);
            }
            else
            {
                throw new UnsupportedEncodingException("Unknown encoding: " +
                                                    encoding);
            }
            len = bis.available();
            bytes = new byte[len];
            len = is.read(bytes, 0, len);
            String ret = new String(bytes, 0, len, charset);
            if (text.length() > end + 2)
            {
                String extra = text.substring(end + 2);

                ret = ret + extra;
            }
            return ret;
        }
        catch (IOException e)
        {
            throw new Exception();
        }
        catch (IllegalArgumentException e)
        {
            throw new UnsupportedEncodingException();
        }
    }
View Full Code Here

            shared.encoding = null;
            shared.userVars.remove("ENCODING");
            return;
        }
        if (!Charset.isSupported(newEncoding))
            throw new UnsupportedEncodingException(newEncoding);
        shared.userVars.put("*ENCODING", newEncoding);
        shared.encoding = newEncoding;
    }
View Full Code Here

TOP

Related Classes of java.io.UnsupportedEncodingException

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.