Demos and Usage of java.lang.String.getBytes(String charsetName)


   1: public class URLEncodeIdMapper implements ResourceIdToPathMapper {
   2:     public String getPathForId(Object resourceId) {
   3:         ...
   4:         String path = resourceId.toString();
   5:         try {
   6:         ...
   7:             path = new String(Base64.encodeBase64(path.getBytes("UTF-8")), "ASCII");
   8:             path = URLEncoder.encode(path);

View Full Code Here
   1: 
   2:     public String getHref()
   3:     {
   4:         ...
   5:  
   6:     public String getContentType()
   7:     {
   8:         ...
   9: 
  10:         String text = engine.getHTML( context, m_page );
  11:         
  12:         ...
  13:         {
  14:             return text.getBytes("UTF-8");

View Full Code Here
   1:         FileData file = new FileManager(con).getFile(form.getFileId());
   2:         String fileName = file.getName();
   3:         ...
   4:         fileName = new String(fileName.getBytes(request.getCharacterEncoding()), "ISO8859_1");
   5:         ...
   6:         String contentDisposition = "attachment; filename=\"" + fileName + "\"";
   7:         response.setHeader("Content-Disposition", contentDisposition);

View Full Code Here
   1:         
   2:         String output = writer.toString();
   3: 
   4:         ...
   5:         return output.getBytes( "UTF-8" );
   6:     }
   7: }

View Full Code Here
   1: 
   2:   public static byte[] stringToBytes(String val, int width)
   3:   {
   4:         ...
   5:       if (val.length() == width)
   6:         return val.getBytes("US-ASCII");
   7:       else if (val.length() > width)
   8:         ...
   9:         return val.substring(0, width).getBytes("US-ASCII");
  10:       else
  11:         ...
  12:         }
  13:         return sb.toString().getBytes("US-ASCII");

View Full Code Here
   1:     public void testParse() throws UnsupportedEncodingException, IOException {
   2:         String record = "   a: b\r\n#c#\r\nc:d\r\n \t\t\r\t\n\te" +
   3:                 "\r\nx:\r\n  # z\r\n\r\n";
   4:         ...
   5:         ANVLRecord r = ANVLRecord.load(new ByteArrayInputStream(
   6:                 record.getBytes("ISO-8859-1")));
   7:         System.out.println(r);
   8:         ...
   9:         r = ANVLRecord.load(new ByteArrayInputStream(
  10:             record.getBytes("ISO-8859-1")));
  11:         System.out.println(r);
  12:         ...
  13:         r = ANVLRecord.load(new ByteArrayInputStream(
  14:             record.getBytes("ISO-8859-1")));

View Full Code Here
   1: 
   2:   public static byte[] stringToBytes(String val, int width)
   3:   {
   4:         ...
   5:       if (val.length() == width)
   6:         return val.getBytes("US-ASCII");
   7:       else if (val.length() > width)
   8:         ...
   9:         return val.substring(0, width).getBytes("US-ASCII");
  10:       else
  11:         ...
  12:         }
  13:         return sb.toString().getBytes("US-ASCII");

View Full Code Here
   1: {
   2:     private static final String ENCODING = "UTF-8";
   3: 
   4:         ...
   5: 
   6:     private String utf8string;
   7: 
   8:         ...
   9: 
  10:     public Utf8CpInfo(String utf8string)
  11:     {

View Full Code Here
   1:     
   2:     public static final String encodeIso(String s) throws UnsupportedEncodingException {
   3:         ...
   4:         return "=?ISO-8859-1?B?" + new String(encode(s.getBytes("ISO-8859-1"))) + "?=";
   5:     }
   6:         ...
   7:     
   8:     public static final String decodeIso(String s) {
   9:         int        idx;

View Full Code Here
   1: 
   2:     private String toRPCString( String src )
   3:     {
   4:         ...
   5: 
   6:     private String fromRPCString( String src )
   7:     {
   8:         ...
   9:         {
  10:             return src.getBytes("UTF-8");
  11:         }

View Full Code Here
   1:     
   2:     protected byte[] plainDecode(String s)
   3:     {
   4:         ...
   5:         {
   6:             return s.getBytes("UTF-8");
   7:         }
   8:         ...
   9: 
  10:     protected byte[] mdDecode(String s, int type)
  11:     {
  12:         ...
  13:             md.reset();
  14:             md.update(s.getBytes("UTF-8"));

View Full Code Here
   1:                 try {
   2:                     String data = getSubString(pos, 1);
   3:                     if (null == data || 0 == data.length()) {
   4:         ...
   5:                     pos++;
   6:                     return data.getBytes("ASCII")[0];
   7:                 } catch (SQLException ex) {
   8:         ...
   9:                 try {
  10:                     String data = getSubString(pos, buf.length);
  11:                     int x = data.length();
  12:         ...
  13:                     }
  14:                     byte[] dbuf = data.getBytes("ASCII");

View Full Code Here
   1: {
   2:     protected String decodeParameters(String value, String characterEncoding)
   3:     throws UnsupportedEncodingException
   4:         ...
   5:         {
   6:             return new String(Base64.decodeBase64(value.getBytes(characterEncoding)), characterEncoding);
   7:         }
   8:         ...
   9:         {
  10:             value = new String(Base64.encodeBase64(value.getBytes(characterEncoding)));
  11:         }

View Full Code Here
   1:     
   2:     public static byte[] getBytes(String str) {
   3:         try {
   4:         ...
   5:             return str.getBytes("UTF8");
   6:         } catch (java.io.UnsupportedEncodingException e) {
   7:         ...
   8:             throw new Error("string to UTF-8 conversion failed: " + e.getMessage());
   9:         }
  10:         ...
  11: 
  12:     public static String getString(byte[] bytes, int offset, int length) {

View Full Code Here