List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:net.officefloor.launch.woof.WoofServletContainerLauncherTest.java
/** * Writes the {@link File} (either creating new or overwriting). * /*from w ww . j a v a2s . c o m*/ * @param directory * Directory to contain the file. * @param fileName * {@link File} name. * @param fileContent * Content for {@link File}. */ private void writeFile(File directory, String fileName, String fileContent) throws IOException { Writer writer = new FileWriter(new File(directory, fileName)); writer.append(fileContent); writer.close(); }
From source file:org.apache.olingo.server.core.debug.DebugTabBody.java
@Override public void appendHtml(final Writer writer) throws IOException { final String body = response == null || response.getContent() == null ? "ODataLibrary: No body." : getContentString();/* ww w. java 2 s . c om*/ switch (responseContent) { case XML: writer.append("<pre class=\"code").append(" xml").append("\">\n"); writer.append(DebugResponseHelperImpl.escapeHtml(body)); writer.append("\n</pre>\n"); break; case JSON: writer.append("<pre class=\"code").append(" json").append("\">\n"); writer.append(DebugResponseHelperImpl.escapeHtml(body)); writer.append("\n</pre>\n"); break; case IMAGE: writer.append("<img src=\"data:").append(response.getHeader(HttpHeader.CONTENT_TYPE)).append(";base64,") .append(body).append("\" />\n"); break; case TEXT: default: writer.append("<pre class=\"code").append("\">\n"); writer.append(DebugResponseHelperImpl.escapeHtml(body)); writer.append("\n</pre>\n"); break; } }
From source file:org.codehaus.groovy.grails.web.util.StreamCharBufferTest.java
public void testWritingStringBuffer() throws IOException { StreamCharBuffer charBuffer = new StreamCharBuffer(10, 0, 10); Writer writer = charBuffer.getWriter(); StringBuffer sb = new StringBuffer("ABCDE12345ABCDEABCDE67890"); writer.append(sb); writer.close();// ww w .j a v a 2s .co m assertEquals(25, charBuffer.size()); assertEquals("ABCDE12345ABCDEABCDE67890", charBuffer.toString()); assertEquals(0, charBuffer.charsAvailable()); assertEquals(0, charBuffer.size()); }
From source file:org.codehaus.groovy.grails.web.util.StreamCharBufferTest.java
public void testWritingStringBuffer2() throws IOException { StreamCharBuffer charBuffer = new StreamCharBuffer(100, 0, 100); Writer writer = charBuffer.getWriter(); StringBuffer sb = new StringBuffer("ABCDE12345ABCDEABCDE67890"); writer.append(sb); writer.close();//from w w w .j ava 2 s . co m assertEquals(25, charBuffer.size()); assertEquals("ABCDE12345ABCDEABCDE67890", charBuffer.toString()); assertEquals(0, charBuffer.charsAvailable()); assertEquals(0, charBuffer.size()); }
From source file:org.codehaus.groovy.grails.web.util.StreamCharBufferTest.java
public void testWritingStringBuilder() throws IOException { StreamCharBuffer charBuffer = new StreamCharBuffer(10, 0, 10); Writer writer = charBuffer.getWriter(); StringBuilder sb = new StringBuilder("ABCDE12345ABCDEABCDE67890"); writer.append(sb); writer.close();//from w w w . ja v a 2 s.c o m assertEquals(25, charBuffer.size()); assertEquals("ABCDE12345ABCDEABCDE67890", charBuffer.toString()); assertEquals(0, charBuffer.charsAvailable()); assertEquals(0, charBuffer.size()); }
From source file:org.codehaus.groovy.grails.web.util.StreamCharBufferTest.java
public void testWritingStringBuilder2() throws IOException { StreamCharBuffer charBuffer = new StreamCharBuffer(100, 0, 100); Writer writer = charBuffer.getWriter(); StringBuilder sb = new StringBuilder("ABCDE12345ABCDEABCDE67890"); writer.append(sb); writer.close();/*w ww. j a va 2 s . co m*/ assertEquals(25, charBuffer.size()); assertEquals("ABCDE12345ABCDEABCDE67890", charBuffer.toString()); assertEquals(0, charBuffer.charsAvailable()); assertEquals(0, charBuffer.size()); }
From source file:com.cognifide.slice.cq.taglib.AnchorTag.java
/** * Appends attribute to a writer if attribute's value is not blank. The attribute is appended in a format: * <tt>' attributeName="attributeValue"'</tt> (with a leading space and double quotes). * // w w w . j a v a 2 s . c o m * @param out output stream to append the attribute to * @param attributeName name of the attribute to be appended * @param attributeValue value of the attribute * @throws IOException if an I/O error occurs. */ protected void apppendAttributeIfNotBlank(Writer out, String attributeName, String attributeValue) throws IOException { if (StringUtils.isNotBlank(attributeValue)) { out.append(" ").append(attributeName).append("=\"").append(attributeValue).append("\""); } }
From source file:org.artifactory.webapp.servlet.TraceLoggingResponse.java
/** * Writes the request info and messages to the response * * @param requestId Request trace context ID * @param methodName HTTP method name//w w w . j a va 2 s .c o m * @param username Authenticated user name * @param requestPath Request repo path id * @throws IOException */ public void sendResponse(String requestId, String methodName, String username, String requestPath) throws IOException { Writer writer = null; try { artifactoryResponse.setContentType(MediaType.TEXT_PLAIN.toString()); writer = artifactoryResponse.getWriter(); writer.append("Request ID: ").append(requestId).append("\n"); writer.append("Repo Path ID: ").append(requestPath).append("\n"); writer.append("Method Name: ").append(methodName).append("\n"); writer.append("User: ").append(username).append("\n"); writer.append("Time: ").append(time).append("\n"); writer.append("Thread: ").append(threadName).append("\n"); writer.flush(); writer.append("Steps: ").append("\n"); IOUtils.writeLines(logAggregator, null, writer); writer.flush(); artifactoryResponse.sendSuccess(); } finally { if (writer != null) { writer.close(); } } }
From source file:fi.okm.mpass.shibboleth.profile.impl.BuildMetaRestResponse.java
/** {@inheritDoc} */ @Override/* w w w . ja v a 2 s. c o m*/ @Nonnull public Event execute(@Nonnull final RequestContext springRequestContext) { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); final HttpServletRequest httpRequest = getHttpServletRequest(); pushHttpResponseProperties(); final HttpServletResponse httpResponse = getHttpServletResponse(); try { final Writer out = new OutputStreamWriter(httpResponse.getOutputStream(), "UTF-8"); if (!HttpMethod.GET.toString().equals(httpRequest.getMethod())) { log.warn("{}: Unsupported method attempted {}", getLogPrefix(), httpRequest.getMethod()); out.append(makeErrorResponse(HttpStatus.SC_METHOD_NOT_ALLOWED, httpRequest.getMethod() + " not allowed", "Only GET is allowed")); } else if (metaDTO != null) { final Gson gson = new Gson(); out.append(gson.toJson(getMetaDTO())); httpResponse.setStatus(HttpStatus.SC_OK); } else { out.append( makeErrorResponse(HttpStatus.SC_NOT_IMPLEMENTED, "Not implemented on the server side", "")); } out.flush(); } catch (IOException e) { log.error("{}: Could not encode the JSON response", getLogPrefix(), e); httpResponse.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE); return ActionSupport.buildEvent(this, EventIds.IO_ERROR); } return ActionSupport.buildProceedEvent(this); }
From source file:annis.gui.exporter.GeneralTextExporter.java
public void convertText(AnnisResultSet queryResult, LinkedList<String> keys, Map<String, String> args, Writer out, int offset) throws IOException { int counter = 0; for (AnnisResult annisResult : queryResult) { Set<Long> matchedNodeIds = annisResult.getGraph().getMatchedNodeIds(); counter++;/* www .j av a 2 s .co m*/ out.append((counter + offset) + ". "); List<AnnisNode> tok = annisResult.getGraph().getTokens(); for (AnnisNode annisNode : tok) { Long tokID = annisNode.getId(); if (matchedNodeIds.contains(tokID)) { out.append("["); out.append(annisNode.getSpannedText()); out.append("]"); } else { out.append(annisNode.getSpannedText()); } //for (Annotation annotation : annisNode.getNodeAnnotations()){ // out.append("/"+annotation.getValue()); //} out.append(" "); } out.append("\n"); } }