List of usage examples for java.io OutputStreamWriter close
public void close() throws IOException
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/pagarFactura/{id}") public String pagarFactura(@PathParam("id") String id) { try {/*from w w w.j av a 2s . c o m*/ URL url = new URL("http://localhost:85/pay"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"id\": \"" + id + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/rechazarFactura/{id}/{motivo}") public String rechazarFactura(@PathParam("id") String id, @PathParam("motivo") String motivo) { try {/*from w ww . j a va2s . c o m*/ URL url = new URL("http://localhost:85/reject/"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"id\": \"" + id + "\",\n" + " \"motivo\": \"" + motivo + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } //return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/recepcionarOc/{id}") public String recepcionarOc(@PathParam("id") String id) { try {// ww w.j a v a 2 s . co m URL url = new URL("http://localhost:83/recepcionar/" + id); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"id\": \"" + id + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } //return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/rechazarOc/{id}/{rechazo}") public String rechazarOc(@PathParam("id") String id, @PathParam("rechazo") String rechazo) { try {// w w w. j ava 2s. c o m URL url = new URL("http://localhost:83/rechazar/" + id); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"rechazo\": \"" + rechazo + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } //return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST //? @Produces("application/json") @Path("/despacharProducto/{id}") public String despacharOc(@PathParam("id") String id) { try {//from w w w . jav a2s .c o m URL url = new URL("http://localhost:83/despachar/" + id); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"id\": \"" + id + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } //return ("[\"Test\", \"Funcionando Bien\"]"); }
From source file:com.mycompany.grupo6ti.GenericResource.java
@DELETE @Produces("application/json") @Path("/anularOc/{id}/{motivo}") public String anularOc(@PathParam("id") String id, @PathParam("motivo") String motivo) { try {//from w w w .java2 s .c o m URL url = new URL("http://localhost:83/anular/" + id); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); //conn.setRequestMethod("DELETE"); conn.setRequestMethod("POST"); // We have to override the post method so we can send data conn.setRequestProperty("X-HTTP-Method-Override", "DELETE"); conn.setDoOutput(true); conn.setDoInput(true); String idJson = "{\n" + " \"anulacion\": \"" + motivo + "\"\n" + "}"; //String idJson2 = "[\"Test\", \"Funcionando Bien\"]"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(idJson); out.flush(); out.close(); if (conn.getResponseCode() >= 400) { is = conn.getErrorStream(); } else { is = conn.getInputStream(); } String result2 = ""; BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { result2 += line; } rd.close(); return result2; } catch (IOException e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien1\"]"); } catch (Exception e) { e.printStackTrace(); return ("[\"Test\", \"Funcionando Bien2\"]"); } }
From source file:com.entertailion.android.shapeways.api.ShapewaysClient.java
/** * Get the access token//from w w w.j a v a 2 s.c om * * @param requestToken * @param requestTokenSecret * @param requestTokenVerifier * @return * @throws Exception */ public Map<String, String> getAccessToken(String requestToken, String requestTokenSecret, String requestTokenVerifier) throws Exception { Log.d(LOG_TAG, "getAccessToken"); URLConnection urlConnection = getUrlConnection(API_URL_BASE + ACCESS_TOKEN_PATH, true); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(urlConnection.getOutputStream()); Request request = new Request(POST); request.addParameter(OAUTH_CONSUMER_KEY, consumerKey); request.addParameter(OAUTH_TOKEN, requestToken); request.addParameter(OAUTH_VERIFIER, requestTokenVerifier); request.sign(API_URL_BASE + ACCESS_TOKEN_PATH, consumerSecret, requestTokenSecret); outputStreamWriter.write(request.toString()); outputStreamWriter.close(); return readParams(urlConnection.getInputStream()); }
From source file:com.nextgis.firereporter.GetFiresService.java
protected boolean writeToFile(File filePath, String sData) { try {// www. ja v a 2s . com FileOutputStream os = new FileOutputStream(filePath, false); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(os); outputStreamWriter.write(sData); outputStreamWriter.close(); return true; } catch (IOException e) { SendError(e.getLocalizedMessage()); return false; } }
From source file:edu.csh.coursebrowser.SchoolActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_course_browser); ListView lv = (ListView) this.findViewById(R.id.schools); this.setTitle("Course Browser"); map_items = new HashMap<String, School>(); map = new ArrayList<String>(); this.sp = getPreferences(MODE_WORLD_READABLE); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map); this.setTitle("Course Browser"); if (!sp.contains("firstRun")) { SharedPreferences.Editor e = sp.edit(); e.putBoolean("firstRun", false); e.commit();//from w ww .ja va2s . com Intent intent = new Intent(SchoolActivity.this, AboutActivity.class); startActivity(intent); } addItem(new School("01", "Saunder's College of Business")); addItem(new School("03", "College of Engineering")); addItem(new School("05", "College of Liberal Arts")); addItem(new School("06", "Applied Science & Technology")); addItem(new School("08", "NTID")); addItem(new School("10", "College of Science")); addItem(new School("11", "Wellness")); addItem(new School("17", "Academic Services")); addItem(new School("20", "Imaging Arts and Sciences")); addItem(new School("30", "Interdisciplinary Studies")); addItem(new School("40", "GCCIS")); addItem(new School("50", "Institute for Sustainability")); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String s = ((TextView) arg1).getText().toString(); final School school = map_items.get(s); new AsyncTask<String, String, String>() { ProgressDialog p; protected void onPreExecute() { p = new ProgressDialog(SchoolActivity.this); p.setTitle("Fetching Info"); p.setMessage("Contacting Server..."); p.setCancelable(false); p.show(); } protected String doInBackground(String... school) { String params = "action=getDepartments&school=" + school[0] + "&quarter=20123"; Log.v("Params", params); URL url; String back = ""; try { url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax.php"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(params); writer.flush(); String line; BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { Log.v("Back:", line); back += line; } writer.close(); reader.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } return back; } protected void onPostExecute(String s) { if (s == null || s == "") { new AlertError(SchoolActivity.this, "IO Error!").show(); return; } try { JSONObject jso = new JSONObject(s); JSONArray jsa = new JSONArray(jso.getString("departments")); ArrayList<Department> depts = new ArrayList<Department>(); for (int i = 0; i < jsa.length(); ++i) { JSONObject obj = new JSONObject(jsa.get(i).toString()); depts.add(new Department(obj.getString("title"), obj.getString("id"), obj.getString("code"))); } } catch (JSONException e) { e.printStackTrace(); new AlertError(SchoolActivity.this, "Invalid JSON From Server").show(); p.dismiss(); return; } Intent intent = new Intent(SchoolActivity.this, DepartmentActivity.class); intent.putExtra("from", school.deptName); intent.putExtra("args", s); intent.putExtra("qCode", sp.getString("quarter", "20122")); startActivity(intent); p.dismiss(); } }.execute(school.deptNum); } }); }
From source file:com.hangum.tadpole.importdb.core.dialog.importdb.csv.CsvToRDBImportDialog.java
private void saveLog() { try {/*w w w . j a va 2 s . c o m*/ if ("".equals(textSQL.getText())) { //$NON-NLS-1$ MessageDialog.openError(null, Messages.CsvToRDBImportDialog_4, Messages.SQLToDBImportDialog_LogEmpty); return; } String filename = PublicTadpoleDefine.TEMP_DIR + userDB.getDisplay_name() + "_SQLImportResult.log"; //$NON-NLS-1$ FileOutputStream fos = new FileOutputStream(filename); OutputStreamWriter bw = new OutputStreamWriter(fos, "UTF-8"); //$NON-NLS-1$ bw.write(textSQL.getText()); bw.close(); String strImportResultLogContent = FileUtils.readFileToString(new File(filename)); downloadExtFile(userDB.getDisplay_name() + "_SQLImportResult.log", strImportResultLogContent);//sbExportData.toString()); //$NON-NLS-1$ } catch (Exception ee) { logger.error("log writer", ee); //$NON-NLS-1$ } }