List of usage examples for java.lang String toString
public String toString()
From source file:com.yh.flume.sink.elasticsearch.ElasticSearchLog4jEventSerializer.java
private void appendBody(XContentBuilder builder, Event event) throws IOException, UnsupportedEncodingException { String body = new String(event.getBody(), charset); // List<String> list = JSON.parseArray(body, String.class); // for (int index = 0; index < list.size(); index++) { // serializerData(builder, fieldList.get(index), list.get(index)); // }/*from w w w . j a v a 2 s .c o m*/ try { JSONObject ob = JSON.parseObject(body); for (int index = 0; index < fieldList.size(); index++) { String key = fieldList.get(index); if (ob.containsKey(key) && ob.get(key) != null) { String value = ob.get(key).toString(); if (StringUtils.isNotBlank(value)) serializerData(builder, key, value.toString()); } } } catch (Exception e) { logger.info(body); e.printStackTrace(); } }
From source file:edu.pdx.konstan2.PortlandLive.responseParserFactory.java
public void parseVehiclesLocationJSON(String response, HashMap<LatLng, Vehicle> vMap) { try {//from w ww .j av a 2 s .c o m JSONParser parser = new JSONParser(); JSONObject jobj = (JSONObject) parser.parse(response.toString()); JSONObject v = (JSONObject) jobj.get("resultSet"); JSONArray arr = (JSONArray) v.get("vehicle"); Iterator<JSONObject> iter = arr.iterator(); while (iter.hasNext()) { Vehicle t = new Vehicle(iter.next()); vMap.put(new LatLng(t.latitude, t.longitude), t); } } catch (Exception e) { } }
From source file:net.hgw4.hal.WebCamClientComm.java
/** * check if input 1 is pressed == 1 ring button * @param port//from w w w .j av a 2s. c om * @return */ public int checkPortStatus(int port) { try { String curport = Integer.toString(port); URL url = new URL("http://" + ip + "/axis-cgi/io/input.cgi?check=" + curport.toString()); //reply with input1=1 o 0 String userPassword = "<user>" + ":" + "<passwd>"; String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes()); URLConnection uc = url.openConnection(); uc.setRequestProperty("Authorization", "Basic " + encoding); InputStream content = (InputStream) uc.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(content)); String str; str = in.readLine(); if (str.contentEquals("input1=1")) { return 1; //high } else if (str.contentEquals("input1=0")) { return 0; //low } in.close(); } catch (MalformedURLException ex) { WebCamClientCommLogger.error(ex); } catch (IOException ex) { WebCamClientCommLogger.error(ex); } return -1; }
From source file:edu.pdx.konstan2.PortlandLive.responseParserFactory.java
public void parseArrivalsXML(String response, HashMap<String, Arrival> sMap) { try {//from w w w. j a v a 2 s. co m JSONParser parser = new JSONParser(); JSONObject jobj = (JSONObject) parser.parse(response.toString()); JSONObject v = (JSONObject) jobj.get("resultSet"); JSONArray arr = (JSONArray) v.get("arrival"); Iterator<JSONObject> iter = arr.iterator(); while (iter.hasNext()) { Arrival t = new Arrival(iter.next()); sMap.put(t.id, t); } } catch (Exception e) { Log.d("exception", e.toString()); } }
From source file:edu.pdx.konstan2.PortlandLive.responseParserFactory.java
public void parseArrivals(String response, HashMap<String, Arrival> sMap) { try {/*from ww w. j ava 2 s .co m*/ JSONParser parser = new JSONParser(); JSONObject jobj = (JSONObject) parser.parse(response.toString()); JSONObject v = (JSONObject) jobj.get("resultSet"); JSONArray arr = (JSONArray) v.get("arrival"); Iterator<JSONObject> iter = arr.iterator(); while (iter.hasNext()) { Arrival t = new Arrival(iter.next()); sMap.put(t.id, t); iter.remove(); } } catch (Exception e) { Log.d("exception", e.toString()); } }
From source file:com.huateng.bo.impl.base.T10601BOTarget.java
public String add(TblCompanyEmployee tblCompanyEmployee, Operator operator) { if (tblCompanyEmployee == null) return "?."; String empId = StringEscapeUtils.escapeSql(tblCompanyEmployee.getEmployeeId()); //???/* w w w.ja v a 2 s . c om*/ String sql = "select EMPLOYEE_NUM from TBL_COMPANY_EMPLOYEE where EMPLOYEE_ID= '" + empId + "'"; List list = commQueryDAO.findBySQLQuery(sql.toString()); if (list != null && list.size() > 0) { return "??"; } String employeeId = GenerateNextId.getNextSequence("TBL_COMPANY_EMPLOYEE"); if (employeeId == null) return "??."; tblCompanyEmployee.setEmployeeId(empId); tblCompanyEmployee.setId(employeeId); tblCompanyEmployeeDAO.save(tblCompanyEmployee); Log.log("????" + operator.getOprId()); return Constants.SUCCESS_CODE; }
From source file:com.facebook.samples.musicdashboard.MusicFetcher.java
public ArrayList<Song> fetchSongs(String jsonString) { ArrayList<Song> songs = new ArrayList<Song>(); try {//from w w w . j ava 2 s .co m //Log.i(TAG, "received jsonString: " + jsonString); String jsonData = new JSONObject(jsonString).getString(JSON_DATA); JSONTokener tokener = new JSONTokener(jsonData.toString()); JSONArray array = (JSONArray) tokener.nextValue(); for (int i = 0; i < array.length(); i++) { JSONObject musicListensJson = array.optJSONObject(i); if (musicListensJson != null) { // Initialize a song object. The details can be // populated in a subsequent fetch. songs.add(new Song(musicListensJson)); } } } catch (JSONException e) { Log.i(TAG, "Exception parsing JSON", e); } return songs; }
From source file:com.github.hdl.tensorflow.yarn.app.LaunchContainerThread.java
@Override /**/*from w w w. j a v a2 s . co m*/ * Connects to CM, sets up container launch context * for shell command and eventually dispatches the container * start request to the CM. */ public void run() { LOG.info("Setting up container launch container for containerid=" + container.getId()); FileSystem fs = null; try { fs = FileSystem.get(appMaster.getConfiguration()); } catch (IOException e) { e.printStackTrace(); } TFContainer tfContainer = new TFContainer(appMaster); Map<String, String> env = tfContainer.setJavaEnv(appMaster.getConfiguration(), null); tfContainer.setNativePath(env); Map<String, LocalResource> localResources = new HashMap<String, LocalResource>(); ApplicationId appId = appMaster.getAppAttempId().getApplicationId(); try { tfContainer.addToLocalResources(fs, tfServerJar, TFContainer.SERVER_JAR_PATH, localResources); if (jniSoDfsPath != null && !jniSoDfsPath.equals("")) { tfContainer.addToLocalResources(fs, jniSoDfsPath, "libbridge.so", localResources); } } catch (IOException e) { e.printStackTrace(); } LOG.info("clusterspec: " + this.serverAddress.getClusterSpec().toString()); //this.serverAddress.getClusterSpec().testClusterString(); ClusterSpec cs = this.serverAddress.getClusterSpec(); StringBuilder command = null; try { command = tfContainer.makeCommands(containerMemory, cs.getBase64EncodedJsonString(), this.serverAddress.getJobName(), this.serverAddress.getTaskIndex()); } catch (JsonProcessingException e) { LOG.info("cluster spec cannot convert into base64 json string!"); e.printStackTrace(); } catch (ClusterSpecException e) { e.printStackTrace(); } List<String> commands = new ArrayList<String>(); commands.add(command.toString()); if (serverAddress != null) { LOG.info(serverAddress.getJobName() + " : " + serverAddress.getAddress() + ":" + serverAddress.getPort()); } ContainerRetryContext containerRetryContext = ContainerRetryContext.newInstance(containerRetryPolicy, containerRetryErrorCodes, containerMaxRetries, containrRetryInterval); for (String cmd : commands) { LOG.info("Container " + container.getId() + " command: " + cmd.toString()); } ContainerLaunchContext ctx = ContainerLaunchContext.newInstance(localResources, env, commands, null, appMaster.getAllTokens().duplicate(), null, containerRetryContext); appMaster.addContainer(container); appMaster.getNMClientAsync().startContainerAsync(container, ctx); }
From source file:com.github.jknack.amd4j.Amd4j.java
/** * Analyze a module by collecting all the dependencies. * * @param name The module name. Required. * @return A module and their dependencies. *//*from w w w .ja va 2 s. c om*/ public Module analyze(final String name) { notNull(name, "The config is required."); return analyze(new Config(name.toString())); }
From source file:com.ChiriChat.DataAccessObject.DAOWebServer.ChiriChatConversacionesDAO.java
@Override public Conversaciones insert(Conversaciones dto) throws Exception { //Enviamos una peticion post al insert de conversacion. HttpPost httPostNuevaConver = new HttpPost("http://chirichatserver.noip.me:85/ws/CreateConversacion"); //Creo el objeto Jason con los datos del contacto que se registra en la app. JSONObject newConver = new JSONObject(); Log.d("Insert Conversacones DAO", "-.--------------------------------------------------------"); try {/* w w w . ja v a 2 s . c o m*/ newConver.put("nombre", dto.getNombre()); newConver.put("owner", dto.getNombre()); ArrayList<Contactos> contactos = dto.getContactos(); JSONArray JSONContactos = new JSONArray(); for (int i = 0; i < contactos.size(); i++) { Contactos c = contactos.get(i); JSONObject j = new JSONObject(c.toString()); JSONContactos.put(i, j); } newConver.put("participantes", JSONContactos); } catch (JSONException e) { e.printStackTrace(); } List parametros = new ArrayList(); //Aade a la peticion post el parametro json, que contiene los datos a insertar.(json) parametros.add(new BasicNameValuePair("json", newConver.toString())); Log.d("JSON de conversacion", newConver.toString()); try { //Creamos la entidad con los datos que le hemos pasado httPostNuevaConver.setEntity(new UrlEncodedFormEntity(parametros)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } //Objeto para poder obtener respuesta del server HttpResponse response = httpClient.execute(httPostNuevaConver); //Obtenemos el codigo de la respuesta int respuesta = response.getStatusLine().getStatusCode(); Log.w("Respueta Insertar conversacion server", "" + respuesta); //Si respuesta 200 devuelvo mi conversacion , si no devolvere null if (respuesta == 200) { //Nos conectamos para recibir los datos de respuesta HttpEntity entity = response.getEntity(); //Creamos el InputStream InputStream is = entity.getContent(); //Leemos el inputStream String temp = StreamToString(is); //Creamos el JSON con la cadena del inputStream Log.d("Cadena JSON", temp.toString()); JSONObject jsonRecibido = new JSONObject(temp); Log.d("InputStreamReader", temp.toString()); Log.d("JSON ==>", jsonRecibido.toString()); Conversaciones conver = new Conversaciones(jsonRecibido); return conver; } return null; }