List of usage examples for java.lang StringBuilder append
@Override public StringBuilder append(char[] str, int offset, int len)
From source file:Main.java
public static void main(String[] arg) { StringBuilder buffer = new StringBuilder(); CharSequence cs = "java2s.com"; buffer.append(cs, 1, 2); System.out.println(buffer);/*from ww w .ja v a 2 s.c o m*/ }
From source file:Main.java
public static void main(String[] arg) { StringBuilder buffer = new StringBuilder(); char[] chars = new char[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; buffer.append(chars, 1, 3); System.out.println(buffer);//ww w . j a v a 2 s . c om }
From source file:com.sxj.spring.modules.mapper.JsonMapper.java
public static void main(String... args) throws JsonProcessingException, IOException { JsonMapper mapper = JsonMapper.nonEmptyMapper(); CJ30 cj30 = new CJ30(); Map<String, String> name = cj30.getName(); name.put("2", ""); name.put("3", "?"); name.put("4", ""); name.put("5", ""); name.put("7", ""); name.put("8", "?"); Map<String, Map<String, Data>> data = cj30.getData(); Map<String, Data> subject1 = new HashMap<String, Data>(); Data d1 = new Data(); d1.setDate("01/14"); d1.setMin(41700);/*from www . jav a2 s . c o m*/ d1.setMax(41780); d1.setAverage(41740); subject1.put("1421164800", d1); Data d2 = new Data(); d2.setDate("01/15"); d2.setMin(41550); d2.setMax(41620); d2.setAverage(41585); subject1.put("1421251200", d2); data.put("2", subject1); Map<String, Data> subject2 = new HashMap<String, Data>(); Data d3 = new Data(); d3.setDate("01/14"); d3.setMin(12450); d3.setMax(12490); d3.setAverage(12470); subject2.put("1421164800", d3); Data d4 = new Data(); d4.setDate("01/15"); d4.setMin(12730); d4.setMax(12770); d4.setAverage(12750); subject2.put("1421251200", d4); data.put("3", subject2); String json = mapper.toJson(cj30); System.out.println(json); FileReader reader = new FileReader(new File("E:\\cj30.js")); char[] buffer = new char[1024]; int read = 0; StringBuilder sb = new StringBuilder(); while ((read = reader.read(buffer)) > 0) { sb.append(buffer, 0, read); } CJ30 fromJson = mapper.fromJson(sb.toString(), CJ30.class); System.out.println(fromJson.getName()); }
From source file:com.foxykeep.parcelablecodegenerator.Main.java
public static void main(String[] args) { File fileInputDir = new File("input"); if (!fileInputDir.exists() || !fileInputDir.isDirectory()) { return;//from w w w . jav a 2 s. c o m } ArrayList<FileInfo> fileInfoList = new ArrayList<FileInfo>(); findJsonFiles(fileInputDir, null, fileInfoList); StringBuilder sb = new StringBuilder(); // For each file in the input folder for (FileInfo fileInfo : fileInfoList) { String fileName = fileInfo.file.getName(); System.out.println("Generating code for " + fileName); char[] buffer = new char[2048]; sb.setLength(0); Reader in; try { in = new InputStreamReader(new FileInputStream(fileInfo.file), "UTF-8"); int read; do { read = in.read(buffer, 0, buffer.length); if (read != -1) { sb.append(buffer, 0, read); } } while (read >= 0); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return; } catch (FileNotFoundException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } String content = sb.toString(); if (content.length() == 0) { System.out.println("file is empty."); return; } try { JSONObject root = new JSONObject(content); // Classes generation String classPackage, className, superClassPackage, superClassName; boolean isSuperClassParcelable, hasSubClasses, isAbstract; classPackage = root.getString("package"); className = root.getString("name"); superClassPackage = JsonUtils.getStringFixFalseNull(root, "superClassPackage"); superClassName = JsonUtils.getStringFixFalseNull(root, "superClassName"); isSuperClassParcelable = root.optBoolean("isSuperClassParcelable"); hasSubClasses = root.optBoolean("hasSubClasses"); if (hasSubClasses) { isAbstract = root.optBoolean("isAbstract"); } else { isAbstract = false; } JSONArray fieldJsonArray = root.optJSONArray("fields"); ArrayList<FieldData> fieldDataList; if (fieldJsonArray != null) { fieldDataList = FieldData.getFieldsData(fieldJsonArray); } else { fieldDataList = new ArrayList<FieldData>(); } // Parcelable generation ParcelableGenerator.generate(fileInfo.dirPath, classPackage, className, superClassPackage, superClassName, isSuperClassParcelable, hasSubClasses, isAbstract, fieldDataList); } catch (JSONException e) { e.printStackTrace(); return; } } }