List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:com.aurel.track.user.LogoffAction.java
private void loginForm(HttpServletResponse response, String customLoginFullPath) throws Exception { Writer writer = null; BufferedReader reader = null; try {// w w w . j ava 2 s .co m URL url = new URL(customLoginFullPath); URLConnection conn = url.openConnection(); reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); writer = response.getWriter(); String line; while ((line = reader.readLine()) != null) { writer.append(line); } } finally { if (writer != null) { writer.flush(); } if (reader != null) { reader.close(); } } }
From source file:com.joliciel.csvLearner.features.BestFeatureFinder.java
public void writeFeatureList(Writer writer, Map<String, Collection<NameValuePair>> bestFeatureMap, int featureListSize) { try {//from ww w . jav a2 s .c om Set<String> features = new TreeSet<String>(); for (Collection<NameValuePair> bestFeatures : bestFeatureMap.values()) { int i = 0; for (NameValuePair pair : bestFeatures) { features.add(pair.getName()); i++; if (i == featureListSize) break; } } for (String feature : features) { writer.append(feature); writer.append("\n"); } writer.flush(); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void writeWordListVariable(Writer writer, int indent, String varName, Iterator<String> words) throws IOException { indent(writer, indent);//from www . j a va2 s. c o m writer.append(varName).append("=\""); while (words.hasNext()) { writer.append(words.next()); if (words.hasNext()) writer.append(' '); } writer.append('"').append(NEWLINE); }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void repeat(Writer writer, int count, char c) throws IOException { if (count <= 0) return;// w w w . ja v a2s . com for (int i = 0; i < count; i++) { writer.append(c); } }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void writeGroupFunctionName(Writer writer, GlobalMetadata<T> global, CommandGroupMetadata group, boolean declare) throws IOException { if (declare) { writer.append("function "); }//ww w . j a v a2 s . c o m //@formatter:off writer.append("_complete_").append(bashize(global.getName())).append("_group_") .append(bashize(group.getName())); //@formatter:on if (declare) { writer.append("() {").append(NEWLINE); } }
From source file:com.tct.emailcommon.internet.Rfc822Output.java
/** * Write a single attachment and its payload *//* w w w .j a v a2s. co m*/ private static void writeOneAttachment(Context context, Writer writer, OutputStream out, Attachment attachment) throws IOException, MessagingException { writeHeader(writer, "Content-Type", attachment.mMimeType + ";\n name=\"" + // TS: junwei-xu 2014-12-05 EMAIL BUGFIX_861660 MOD_S MimeUtility.foldAndEncode2(attachment.mFileName, "ContentType".length() + 2) + "\""); // TS: junwei-xu 2014-12-05 EMAIL BUGFIX_861660 MOD_E writeHeader(writer, "Content-Transfer-Encoding", "base64"); // Most attachments (real files) will send Content-Disposition. The suppression option // is used when sending calendar invites. if ((attachment.mFlags & Attachment.FLAG_ICS_ALTERNATIVE_PART) == 0) { writeHeader(writer, "Content-Disposition", "attachment;" + "\n filename=\"" + // TS: junwei-xu 2014-12-05 EMAIL BUGFIX_861660 MOD_S MimeUtility.foldAndEncode2(attachment.mFileName, "ContentType".length() + 2) // TS: junwei-xu 2014-12-05 EMAIL BUGFIX_861660 MOD_E + "\";" + "\n size=" + Long.toString(attachment.mSize)); } if (attachment.mContentId != null) { writeHeader(writer, "Content-ID", attachment.mContentId); } writer.append("\r\n"); // Set up input stream and write it out via base64 InputStream inStream = null; try { // Use content, if provided; otherwise, use the contentUri if (attachment.mContentBytes != null) { inStream = new ByteArrayInputStream(attachment.mContentBytes); } else { // First try the cached file final String cachedFile = attachment.getCachedFileUri(); if (!TextUtils.isEmpty(cachedFile)) { final Uri cachedFileUri = Uri.parse(cachedFile); try { inStream = context.getContentResolver().openInputStream(cachedFileUri); } catch (FileNotFoundException e) { // Couldn't open the cached file, fall back to the original content uri inStream = null; LogUtils.i(TAG, "Rfc822Output#writeOneAttachment(), failed to load" + "cached file, falling back to: %s", attachment.getContentUri()); } } if (inStream == null) { // try to open the file final Uri fileUri = Uri.parse(attachment.getContentUri()); inStream = context.getContentResolver().openInputStream(fileUri); } } // switch to output stream for base64 text output writer.flush(); Base64OutputStream base64Out = new Base64OutputStream(out, Base64.CRLF | Base64.NO_CLOSE); // copy base64 data and close up IOUtils.copy(inStream, base64Out); base64Out.close(); // The old Base64OutputStream wrote an extra CRLF after // the output. It's not required by the base-64 spec; not // sure if it's required by RFC 822 or not. out.write('\r'); out.write('\n'); out.flush(); } catch (FileNotFoundException fnfe) { // Ignore this - empty file is OK LogUtils.e(TAG, fnfe, "Rfc822Output#writeOneAttachment(), FileNotFoundException" + "when sending attachment"); } catch (IOException ioe) { LogUtils.e(TAG, ioe, "Rfc822Output#writeOneAttachment(), IOException" + "when sending attachment"); throw new MessagingException("Invalid attachment.", ioe); } }
From source file:com.ontotext.s4.TwitterVisualization.processingTweets.ProcessingTweets.java
/** * Process all documents into the raw tweets folder. Save processed tweets * into the processed tweets Folder.//from w w w . j a v a 2s.c o m */ public void ProcessTweets() { // get all documents in a folder File f = new File(rawTweetsFolder); File[] documents = f.listFiles(); // if (documents == null) { logger.info("There are no files to process"); return; } // the output File results = new File(processedTweetsFolder); if (!results.exists()) { results.mkdirs(); } Writer w = null; for (File document : documents) { try { if (document.isDirectory() || !document.canRead()) { continue; } logger.info("Just send " + document.getName() + " for processing."); // annotate each file String result = ProcessThisTweet(new String(Files.readAllBytes(document.toPath()))); logger.info("Received " + document.getName()); w = new OutputStreamWriter(new FileOutputStream(processedTweetsFolder + "/" + document.getName())); w.append(result); } catch (FileNotFoundException e) { logger.debug(e); } catch (IOException e) { logger.debug(e); } finally { try { w.close(); } catch (IOException e) { logger.debug(e); } catch (Exception e2) { logger.debug(e2); } } } }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void writeGroupCase(Writer writer, GlobalMetadata<T> global, CommandGroupMetadata group, int indent) throws IOException { // Start the case indent(writer, indent);/* w w w.ja va 2s .co m*/ writer.append(group.getName()).append(')').append(NEWLINE); indent += 2; // Call the function writeGroupFunctionCall(writer, global, group, indent); // Want to return and terminate the case indent(writer, indent); writer.append("return $?").append(NEWLINE); indent(writer, indent); writer.append(";;").append(NEWLINE); }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void writeCommandFunctionName(Writer writer, GlobalMetadata<T> global, CommandGroupMetadata group, CommandMetadata command, boolean declare) throws IOException { if (declare) { writer.append("function "); }//ww w .j a v a 2 s . c o m //@formatter:off writer.append("_complete_").append(bashize(global.getName())); if (group != null) { writer.append("_group_").append(bashize(group.getName())); } writer.append("_command_").append(bashize(command.getName())); //@formatter:on if (declare) { writer.append("() {").append(NEWLINE); } }
From source file:com.xpn.xwiki.render.filter.StyleFilter.java
public void handleMatch(StringBuffer buffer, MatchResult result, FilterContext context) { String command = result.group(1); if (command != null) { // {$peng} are variables not macros. if (!command.startsWith("$")) { MacroParameter mParams = context.getMacroParameter(); switch (result.groups()) { case 3: mParams.setContent(result.group(3)); mParams.setContentStart(result.beginOffset(3)); mParams.setContentEnd(result.endOffset(3)); case 2: mParams.setParams(result.group(2)); }/* w w w . jav a2s. c o m*/ mParams.setStart(result.beginOffset(0)); mParams.setEnd(result.endOffset(0)); // @DANGER: recursive calls may replace macros in included source code try { if (command.equals("style") && (mParams.getContent() != null)) { // We need to handle recursivity here String content = mParams.getContent(); Pattern pattern = Pattern.compile("\\{" + command + ".*?\\}"); // This code allows to find the real end tag Matcher matcher = pattern.matcher(content); int startTagNumber = 1; int endPosition = content.length(); while (matcher.find()) { String match = matcher.group(); if (match.equals("{" + command + "}")) { startTagNumber--; if (startTagNumber == 0) { endPosition = matcher.start(); break; } } else { startTagNumber++; } } // Get the content up to the real end tag String realContent = content.substring(0, endPosition); // Execute any nested macros and filters mParams.setContent(realContent); Writer writer = new StringBufferWriter(buffer); Macro macro = (Macro) getMacroRepository().get(command); // Execute the macro resulting content macro.execute(writer, mParams); if (content.length() != endPosition) { // Get the content after the real end tag String nextContent = content.substring(endPosition + 2 + command.length()) + "{style}"; // Execute other macros on content after the real end tag writer.append(nextContent); } } else if (getMacroRepository().containsKey(command)) { Macro macro = (Macro) getMacroRepository().get(command); // recursively filter macros within macros if (null != mParams.getContent()) { mParams.setContent(mParams.getContent()); } Writer writer = new StringBufferWriter(buffer); macro.execute(writer, mParams); } else { buffer.append(result.group(0)); return; } } catch (IllegalArgumentException e) { buffer.append("<div class=\"error\">" + command + ": " + e.getMessage() + "</div>"); } catch (Throwable e) { log.warn("MacroFilter: unable to format macro: " + result.group(1), e); buffer.append("<div class=\"error\">" + command + ": " + e.getMessage() + "</div>"); return; } } else { buffer.append("<"); buffer.append(command.substring(1)); buffer.append(">"); } } else { buffer.append(result.group(0)); } }