List of usage examples for java.io OutputStreamWriter flush
public void flush() throws IOException
From source file:org.alfresco.repo.transfer.RepoTransferReceiverImpl.java
/** * Generate the requsite//ww w. j a v a 2 s . c om */ public void generateRequsite(String transferId, OutputStream out) throws TransferException { log.debug("Generate Requsite for transfer:" + transferId); try { File snapshotFile = getSnapshotFile(transferId); if (snapshotFile.exists()) { log.debug("snapshot does exist"); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); SAXParser parser = saxParserFactory.newSAXParser(); OutputStreamWriter dest = new OutputStreamWriter(out, "UTF-8"); XMLTransferRequsiteWriter writer = new XMLTransferRequsiteWriter(dest); TransferManifestProcessor processor = manifestProcessorFactory .getRequsiteProcessor(RepoTransferReceiverImpl.this, transferId, writer); XMLTransferManifestReader reader = new XMLTransferManifestReader(processor); /** * Now run the parser */ parser.parse(snapshotFile, reader); /** * And flush the destination in case any content remains in the writer. */ dest.flush(); } log.debug("Generate Requsite done transfer:" + transferId); } catch (Exception ex) { if (TransferException.class.isAssignableFrom(ex.getClass())) { throw (TransferException) ex; } else { throw new TransferException(MSG_ERROR_WHILE_GENERATING_REQUISITE, ex); } } }
From source file:com.techventus.server.voice.Voice.java
/** * Enables/disables the call Announcement setting (general for all phones). * * @param announceCaller <br/>/*from w w w. j a va2 s .c om*/ * true Announces caller's name and gives answering options <br/> * false Directly connects calls when phones are answered * @return the raw response of the disable action. * @throws IOException Signals that an I/O exception has occurred. */ public String setCallPresentation(boolean announceCaller) throws IOException { String out = ""; URL requestURL = new URL(generalSettingsURLString); /** 0 for enable, 1 for disable **/ String announceCallerStr = ""; if (announceCaller) { announceCallerStr = "0"; if (PRINT_TO_CONSOLE) System.out.println("Turning caller announcement on."); } else { announceCallerStr = "1"; if (PRINT_TO_CONSOLE) System.out.println("Turning caller announcement off."); } String paraString = ""; paraString += URLEncoder.encode("directConnect", enc) + "=" + URLEncoder.encode(announceCallerStr, enc); paraString += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + URLEncoder.encode(rnrSEE, enc); URLConnection conn = requestURL.openConnection(); conn.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken); conn.setRequestProperty("User-agent", USER_AGENT); conn.setDoOutput(true); conn.setDoInput(true); OutputStreamWriter callwr = new OutputStreamWriter(conn.getOutputStream()); callwr.write(paraString); callwr.flush(); BufferedReader callrd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = callrd.readLine()) != null) { out += line + "\n\r"; } callwr.close(); callrd.close(); if (out.equals("")) { throw new IOException("No Response Data Received."); } return out; }
From source file:com.techventus.server.voice.Voice.java
/** * Mark a Conversation with a known Message ID as read. * * @param msgID the msg id/*from w w w .ja va 2s. co m*/ * @return the string * @throws IOException Signals that an I/O exception has occurred. */ public String markAsRead(String msgID) throws IOException { String out = ""; StringBuffer calldata = new StringBuffer(); // POST /voice/inbox/mark/ // messages=[messageID] // &read=1 // &_rnr_se=[pull from page] calldata.append("messages="); calldata.append(URLEncoder.encode(msgID, enc)); calldata.append("&read=1"); calldata.append("&_rnr_se="); calldata.append(URLEncoder.encode(rnrSEE, enc)); URL callURL = new URL(markAsReadString); URLConnection callconn = callURL.openConnection(); callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken); callconn.setRequestProperty("User-agent", USER_AGENT); callconn.setDoOutput(true); OutputStreamWriter callwr = new OutputStreamWriter(callconn.getOutputStream()); callwr.write(calldata.toString()); callwr.flush(); BufferedReader callrd = new BufferedReader(new InputStreamReader(callconn.getInputStream())); String line; while ((line = callrd.readLine()) != null) { out += line + "\n\r"; } callwr.close(); callrd.close(); if (out.equals("")) { throw new IOException("No Response Data Received."); } return out; }
From source file:com.techventus.server.voice.Voice.java
/** * Mark a Conversation with a known Message ID as unread. * * @param msgID the msg id/*from w w w . j a v a2 s.c o m*/ * @return the string * @throws IOException Signals that an I/O exception has occurred. */ public String markUnRead(String msgID) throws IOException { String out = ""; StringBuffer calldata = new StringBuffer(); // POST /voice/inbox/mark/ // messages=[messageID] // &read=0 // &_rnr_se=[pull from page] calldata.append("messages="); calldata.append(URLEncoder.encode(msgID, enc)); calldata.append("&read=0"); calldata.append("&_rnr_se="); calldata.append(URLEncoder.encode(rnrSEE, enc)); URL callURL = new URL("https://www.google.com/voice/b/0/inbox/mark"); URLConnection callconn = callURL.openConnection(); callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken); callconn.setRequestProperty("User-agent", USER_AGENT); callconn.setDoOutput(true); OutputStreamWriter callwr = new OutputStreamWriter(callconn.getOutputStream()); callwr.write(calldata.toString()); callwr.flush(); BufferedReader callrd = new BufferedReader(new InputStreamReader(callconn.getInputStream())); String line; while ((line = callrd.readLine()) != null) { out += line + "\n\r"; } callwr.close(); callrd.close(); if (out.equals("")) { throw new IOException("No Response Data Received."); } return out; }
From source file:com.techventus.server.voice.Voice.java
/** * Delete message.//from ww w .j a va 2 s. c o m * * @param msgID the msg id * @return the string * @throws IOException Signals that an I/O exception has occurred. */ public String deleteMessage(String msgID) throws IOException { String out = ""; StringBuffer calldata = new StringBuffer(); // POST /voice/inbox/deleteMessages/ // messages=[messageID] // &trash=1 // &_rnr_se=[pull from page] calldata.append("messages="); calldata.append(URLEncoder.encode(msgID, enc)); calldata.append("&trash=1"); calldata.append("&_rnr_se="); calldata.append(URLEncoder.encode(rnrSEE, enc)); URL callURL = new URL("https://www.google.com/voice/b/0/inbox/deleteMessages/"); URLConnection callconn = callURL.openConnection(); callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken); callconn.setRequestProperty("User-agent", USER_AGENT); callconn.setDoOutput(true); OutputStreamWriter callwr = new OutputStreamWriter(callconn.getOutputStream()); callwr.write(calldata.toString()); callwr.flush(); BufferedReader callrd = new BufferedReader(new InputStreamReader(callconn.getInputStream())); String line; while ((line = callrd.readLine()) != null) { out += line + "\n\r"; } callwr.close(); callrd.close(); if (out.equals("")) { throw new IOException("No Response Data Received."); } return out; }
From source file:com.techventus.server.voice.Voice.java
/** * Place a call.// ww w. j ava2 s.co m * * @param originNumber * the origin number * @param destinationNumber * the destination number * @param phoneType * the phone type, this is a number such as 1,2,7 formatted as a String * @return the raw response string received from Google Voice. * @throws IOException * Signals that an I/O exception has occurred. */ public String call(String originNumber, String destinationNumber, String phoneType) throws IOException { String out = ""; StringBuffer calldata = new StringBuffer(); // POST /voice/call/connect/ // outgoingNumber=[number to call] // &forwardingNumber=[forwarding number] // &subscriberNumber=undefined // &phoneType=[phone type from google] // &remember=0 // &_rnr_se=[pull from page] calldata.append("outgoingNumber="); calldata.append(URLEncoder.encode(destinationNumber, enc)); calldata.append("&forwardingNumber="); calldata.append(URLEncoder.encode(originNumber, enc)); calldata.append("&subscriberNumber=undefined"); calldata.append("&phoneType="); calldata.append(URLEncoder.encode(phoneType, enc)); calldata.append("&remember=0"); calldata.append("&_rnr_se="); calldata.append(URLEncoder.encode(rnrSEE, enc)); URL callURL = new URL("https://www.google.com/voice/b/0/call/connect/"); URLConnection callconn = callURL.openConnection(); callconn.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken); callconn.setRequestProperty("User-agent", USER_AGENT); callconn.setDoOutput(true); OutputStreamWriter callwr = new OutputStreamWriter(callconn.getOutputStream()); callwr.write(calldata.toString()); callwr.flush(); BufferedReader callrd = new BufferedReader(new InputStreamReader(callconn.getInputStream())); String line; while ((line = callrd.readLine()) != null) { out += line + "\n\r"; } callwr.close(); callrd.close(); if (out.equals("")) { throw new IOException("No Response Data Received."); } return out; }
From source file:edu.utsa.sifter.IndexResource.java
@Path("export") @GET/*from w ww.ja v a2 s . c o m*/ @Produces({ "text/csv" }) public StreamingOutput getDocExport(@QueryParam("id") final String searchID) throws IOException { final SearchResults results = searchID != null ? State.Searches.get(searchID) : null; // System.err.println("exporting results for query " + searchID); if (results != null) { final IndexInfo info = State.IndexLocations.get(results.IndexID); final IndexSearcher searcher = getCommentsSearcher(results.IndexID + "comments-idx", info.Path); final BookmarkSearcher markStore = searcher == null ? null : new BookmarkSearcher(searcher, null); final ArrayList<Result> docs = results.retrieve(0, results.TotalHits); // System.err.println("query export has " + results.TotalHits + " items, size of array is " + hits.size()); final StreamingOutput stream = new StreamingOutput() { public void write(OutputStream output) throws IOException, WebApplicationException { final OutputStreamWriter writer = new OutputStreamWriter(output, "UTF-8"); try { writer.write( "ID,Score,Name,Path,Extension,Size,Modified,Accessed,Created,Cell,CellDistance,Bookmark Created,Bookmark Comment\n"); int n = 0; for (Result doc : docs) { if (markStore != null) { markStore.executeQuery(parseQuery(doc.ID, "Docs")); final ArrayList<Bookmark> marks = markStore.retrieve(); if (marks == null) { writeRecord(doc, null, writer); ++n; } else { for (Bookmark mark : marks) { writeRecord(doc, mark, writer); ++n; } } } else { writeRecord(doc, null, writer); ++n; } } // System.err.println("Streamed out " + n + " items"); writer.flush(); } catch (Exception e) { throw new WebApplicationException(e); } } }; return stream; // return Response.ok(stream, "text/csv").header("content-disposition","attachment; filename=\"export.csv\"").build(); } else { HttpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); return null; } }
From source file:com.techventus.server.voice.Voice.java
/** * Use this login method to login - use captchaAnswer to answer a captcha challenge * @param pCaptchaAnswer (optional) String entered by the user as an answer to a CAPTCHA challenge. - null to make a normal login attempt * @param pCaptchaToken (optional) token which matches the response/url from the captcha challenge * @throws IOException if login encounters a connection error *///from w w w. ja v a2 s . c om public void login(String pCaptchaAnswer, String pCaptchaToken) throws IOException { String data = URLEncoder.encode("accountType", enc) + "=" + URLEncoder.encode(account_type, enc); data += "&" + URLEncoder.encode("Email", enc) + "=" + URLEncoder.encode(user, enc); data += "&" + URLEncoder.encode("Passwd", enc) + "=" + URLEncoder.encode(pass, enc); data += "&" + URLEncoder.encode("service", enc) + "=" + URLEncoder.encode(SERVICE, enc); data += "&" + URLEncoder.encode("source", enc) + "=" + URLEncoder.encode(source, enc); if (pCaptchaAnswer != null && pCaptchaToken != null) { data += "&" + URLEncoder.encode("logintoken", enc) + "=" + URLEncoder.encode(pCaptchaToken, enc); data += "&" + URLEncoder.encode("logincaptcha", enc) + "=" + URLEncoder.encode(pCaptchaAnswer, enc); } // Send data URL url = new URL(loginURLString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("User-agent", USER_AGENT); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); // Get the response conn.connect(); int responseCode = conn.getResponseCode(); if (PRINT_TO_CONSOLE) System.out.println(loginURLString + " - " + conn.getResponseMessage()); InputStream is; if (responseCode == 200) { is = conn.getInputStream(); } else { is = conn.getErrorStream(); } InputStreamReader isr = new InputStreamReader(is); BufferedReader rd = new BufferedReader(isr); String line; String completelineDebug = ""; /* * A failure response contains an error code and a URL to an error page that can be displayed to the user. * If the error code is a CAPTCHA challenge, the response also includes a URL to a CAPTCHA image and a special * token. Your application should be able to solicit an answer from the user and then retry the login request. * To display the CAPTCHA image to the user, prefix the CaptchaUrl value with "http://www.google.com/accounts/", * for example: " http://www.google.com/accounts/Captcha?ctoken=HiteT4b0Bk5Xg18_AcVoP6-yFkHPibe7O9EqxeiI7lUSN". */ String lErrorString = "Unknown Connection Error."; // ex: Error=CaptchaRequired // String AuthToken = null; while ((line = rd.readLine()) != null) { completelineDebug += line + "\n"; if (line.contains("Auth=")) { this.authToken = line.split("=", 2)[1].trim(); if (PRINT_TO_CONSOLE) { System.out.println("Logged in to Google - Auth token received"); } } else if (line.contains("Error=")) { lErrorString = line.split("=", 2)[1].trim(); //error = getErrorEnumByCode(lErrorString); error = ERROR_CODE.valueOf(lErrorString); if (PRINT_TO_CONSOLE) System.out.println("Login error - " + lErrorString); } if (line.contains("CaptchaToken=")) { captchaToken = line.split("=", 2)[1].trim(); } if (line.contains("CaptchaUrl=")) { captchaUrl = "http://www.google.com/accounts/" + line.split("=", 2)[1].trim(); } if (line.contains("Url=")) { captchaUrl2 = line.split("=", 2)[1].trim(); } } wr.close(); rd.close(); // if (PRINT_TO_CONSOLE){ // System.out.println(completelineDebug); // } if (this.authToken == null) { AuthenticationException.throwProperException(error, captchaToken, captchaUrl); } String response = this.getRawPhonesInfo(); int phoneIndex = response.indexOf("gc-user-number-value\">"); this.phoneNumber = response.substring(phoneIndex + 22, phoneIndex + 36); this.phoneNumber = this.phoneNumber.replaceAll("[^a-zA-Z0-9]", ""); if (this.phoneNumber.indexOf("+") == -1) { this.phoneNumber = "+1" + this.phoneNumber; } }
From source file:org.apromore.portal.dialogController.similarityclusters.visualisation.ClusterVisualisationController.java
private void writeVisualisationJSON(final OutputStream os) throws JSONException, IOException { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(os, "UTF-8"); JSONWriter jsonWriter = new JSONWriter(outputStreamWriter); JSONArray edgesArray = new JSONArray(); jsonWriter.object().key("nodes").array(); // Current index of the node long index = 0; for (ClusterSummaryType clusterInfo : clusterResult) { Integer clusterId = clusterInfo.getClusterId(); Integer medoidId = clusterInfo.getMedoidId(); writeNode(jsonWriter, clusterId, clusterInfo.getMedoidId(), clusterInfo.getClusterLabel(), true, clusterInfo.getClusterSize()); // We need this index to build the edges afterwards indexMap.put(medoidId, index);//from w w w. j a v a 2s. c o m index++; List<FragmentData> fragments = getService().getCluster(clusterInfo.getClusterId()).getFragments(); for (FragmentData fragmentData : fragments) { if (!isMedoid(medoidId, fragmentData.getFragmentId())) { // TODO: MAKE SURE if (fragmentData.getDistance() > 0) { writeNode(jsonWriter, clusterId, fragmentData.getFragmentId(), fragmentData.getFragmentLabel(), false, fragmentData.getFragmentSize()); // Omit all negative distances, as they are the medoids // if (fragmentData.getDistance() > 0) { JSONObject edgeObject = buildEdgeObject(indexMap.get(medoidId), index, fragmentData.getDistance(), false); edgesArray.put(edgeObject); // } index++; } } } } jsonWriter.endArray().key("edges").value(edgesArray); jsonWriter.endObject(); outputStreamWriter.flush(); }
From source file:edu.utsa.sifter.IndexResource.java
@Path("exporthits") @GET/*from ww w . j a va2 s . c o m*/ @Produces({ "text/csv" }) public StreamingOutput getHitExport(@QueryParam("id") final String searchID) throws IOException, InterruptedException, ExecutionException { final SearchResults results = searchID != null ? State.Searches.get(searchID) : null; // System.err.println("exporting results for query " + searchID); if (results != null) { final IndexInfo info = State.IndexLocations.get(results.IndexID); final IndexSearcher searcher = getCommentsSearcher(results.IndexID + "comments-idx", info.Path); final BookmarkSearcher markStore = searcher == null ? null : new BookmarkSearcher(searcher, null); final ArrayList<SearchHit> hits = results.getSearchHits(); // System.err.println("query export has " + results.TotalHits + " items, size of array is " + hits.size()); final StreamingOutput stream = new StreamingOutput() { public void write(OutputStream output) throws IOException, WebApplicationException { final OutputStreamWriter writer = new OutputStreamWriter(output, "UTF-8"); try { writer.write( "ID,Score,Name,Path,Extension,Size,Modified,Accessed,Created,Cell,CellDistance,Start,End,Snippet,Bookmark Created,Bookmark Comment\n"); int n = 0; for (SearchHit hit : hits) { if (markStore != null) { markStore.executeQuery(parseQuery(hit.ID(), "Docs")); final ArrayList<Bookmark> marks = markStore.retrieve(); if (marks == null) { writeHitRecord(hit, null, writer); ++n; } else { for (Bookmark mark : marks) { writeHitRecord(hit, mark, writer); ++n; } } } else { writeHitRecord(hit, null, writer); ++n; } } // System.err.println("Streamed out " + n + " items"); writer.flush(); } catch (Exception e) { throw new WebApplicationException(e); } } }; return stream; // return Response.ok(stream, "text/csv").header("content-disposition","attachment; filename=\"export.csv\"").build(); } else { HttpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); return null; } }