List of usage examples for java.io StringWriter flush
public void flush()
From source file:org.directwebremoting.drapgen.generate.gi.GiType.java
/** * @param directory Where to write the xml * @throws java.io.IOException If writing fails *//*from w w w. j a v a 2s. c o m*/ public void writeDOM(String directory) throws IOException { FileWriter out = null; try { Transformer transformer = factory.newTransformer(); Source source = new DOMSource(document); StringWriter xml = new StringWriter(); StreamResult result = new StreamResult(xml); transformer.transform(source, result); xml.flush(); String domName = xmlClassName.replaceAll("/", "."); File domFile = new File(directory + "org.directwebremoting.proxy." + domName); out = new FileWriter(domFile); out.append(xml.toString()); } catch (TransformerException ex) { SourceLocator locator = ex.getLocator(); log.fatal("Failed to transform", ex); log.warn("Line: " + locator.getLineNumber() + ", Column: " + locator.getColumnNumber()); log.warn("PublicId: " + locator.getPublicId()); log.warn("SystemId: " + locator.getSystemId()); } finally { if (out != null) { out.close(); } } }
From source file:org.openhab.binding.samsungtv.internal.protocol.RemoteControllerLegacy.java
private String createRegistrationPayload(String ip) throws IOException { /*/*ww w. j a va 2 s. c om*/ * Payload starts with 2 bytes: 0x64 and 0x00, then comes 3 strings * encoded with base64 algorithm. Every string is preceded by 2-bytes * field containing encoded string length. * * These three strings are as follow: * * remote control device IP, unique ID value to distinguish * controllers, name it will be displayed as controller name. */ StringWriter w = new StringWriter(); w.append((char) 0x64); w.append((char) 0x00); writeBase64String(w, ip); writeBase64String(w, uniqueId); writeBase64String(w, appName); w.flush(); return w.toString(); }
From source file:gmgen.plugin.PlayerCharacterOutput.java
String getExportToken(String token) { try {// www. j av a 2s .c o m StringWriter retWriter = new StringWriter(); BufferedWriter bufWriter = new BufferedWriter(retWriter); ExportHandler export = new ExportHandler(new File("")); export.replaceTokenSkipMath(pc, token, bufWriter); retWriter.flush(); try { bufWriter.flush(); } catch (IOException e) { // TODO - Handle Exception } return retWriter.toString(); } catch (Exception e) { System.out.println("Failure fetching token: " + token); return ""; } }
From source file:io.restassured.internal.http.EncoderRegistry.java
/** * Default handler used for a plain text content-type. Acceptable argument * types are:/* ww w .ja v a 2 s . c o m*/ * <ul> * <li>Closure</li> * <li>Writable</li> * <li>Reader</li> * </ul> * For Closure argument, a {@link PrintWriter} is passed as the single * argument to the closure. Any data sent to the writer from the * closure will be sent to the request content body. * * @param data * @return an {@link HttpEntity} encapsulating this request data * @throws IOException */ public HttpEntity encodeText(Object contentType, Object data) throws IOException { String contentTypeAsString = contentTypeToString(contentType); if (data instanceof Closure) { StringWriter out = new StringWriter(); PrintWriter writer = new PrintWriter(out); ((Closure) data).call(writer); writer.close(); out.flush(); data = out; } else if (data instanceof Writable) { StringWriter out = new StringWriter(); ((Writable) data).writeTo(out); out.flush(); data = out; } else if (data instanceof Reader && !(data instanceof BufferedReader)) { data = new BufferedReader((Reader) data); } else if (data instanceof File) { data = toString((File) data, contentTypeAsString); } if (data instanceof BufferedReader) { StringWriter out = new StringWriter(); DefaultGroovyMethods.leftShift(out, (BufferedReader) data); data = out; } // if data is a String, we are already covered. return createEntity(contentTypeAsString, data); }
From source file:org.apache.olingo.client.core.it.AbstractTestITCase.java
protected void debugFeed(final Feed feed, final String message) { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); getClient().getSerializer().feed(feed, writer); writer.flush(); LOG.debug(message + "\n{}", writer.toString()); }//from w w w .j ava2 s. c o m }
From source file:org.apache.olingo.client.core.it.AbstractTestITCase.java
protected void debugEntry(final Entry entry, final String message) { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); getClient().getSerializer().entry(entry, writer); writer.flush(); LOG.debug(message + "\n{}", writer.toString()); }//from ww w. ja v a 2 s .co m }
From source file:org.apache.cayenne.query.Ordering.java
@Override public String toString() { StringWriter buffer = new StringWriter(); PrintWriter pw = new PrintWriter(buffer); XMLEncoder encoder = new XMLEncoder(pw); encodeAsXML(encoder);// ww w . j ava 2 s . c om pw.close(); buffer.flush(); return buffer.toString(); }
From source file:org.jbpm.workbench.forms.display.backend.provider.FreemakerFormProvider.java
protected StaticHTMLFormRenderingSettings renderForm(String name, InputStream src, Map<String, Object> renderContext) { if (src == null) { return null; }// w ww . j a v a 2 s. com String htmlTemplate = ""; StringWriter writer = null; InputStreamReader source = null; try { Configuration cfg = new Configuration(); BeansWrapper defaultInstance = new BeansWrapper(); defaultInstance.setSimpleMapWrapper(true); cfg.setObjectWrapper(defaultInstance); cfg.setTemplateUpdateDelay(0); source = new InputStreamReader(src); Template temp = new Template(name, source, cfg); writer = new StringWriter(); temp.process(renderContext, writer); writer.flush(); htmlTemplate = writer.getBuffer().toString(); } catch (Exception e) { throw new RuntimeException("Failed to process form template", e); } finally { IOUtils.closeQuietly(writer); IOUtils.closeQuietly(source); } return new StaticHTMLFormRenderingSettings(htmlTemplate); }
From source file:org.apache.axis2.deployment.ModuleBuilder.java
/** * Fill in the AxisModule I'm holding from the module.xml configuration. * * @throws DeploymentException if there's a problem with the module.xml *///w ww . ja v a 2 s. co m public void populateModule() throws DeploymentException { try { OMElement moduleElement = buildOM(); // Setting Module Class , if it is there OMAttribute moduleClassAtt = moduleElement.getAttribute(new QName(TAG_CLASS_NAME)); // processing Parameters // Processing service level parameters Iterator itr = moduleElement.getChildrenWithName(new QName(TAG_PARAMETER)); processParameters(itr, module, module.getParent()); Parameter childFirstClassLoading = module .getParameter(Constants.Configuration.ENABLE_CHILD_FIRST_CLASS_LOADING); if (childFirstClassLoading != null) { DeploymentClassLoader deploymentClassLoader = (DeploymentClassLoader) module.getModuleClassLoader(); if (JavaUtils.isTrueExplicitly(childFirstClassLoading.getValue())) { deploymentClassLoader.setChildFirstClassLoading(true); } else if (JavaUtils.isFalseExplicitly(childFirstClassLoading.getValue())) { deploymentClassLoader.setChildFirstClassLoading(false); } } if (moduleClassAtt != null) { String moduleClass = moduleClassAtt.getAttributeValue(); if ((moduleClass != null) && !"".equals(moduleClass)) { loadModuleClass(module, moduleClass); } } // Get our name and version. If this is NOT present, we'll try to figure it out // from the file name (e.g. "addressing-1.0.mar"). If the attribute is there, we // always respect it. //TODO: Need to check whether ths name is getting overridden by the file name of the MAR OMAttribute nameAtt = moduleElement.getAttribute(new QName("name")); if (nameAtt != null) { String moduleName = nameAtt.getAttributeValue(); if (moduleName != null && !"".equals(moduleName)) { module.setName(moduleName); } } if (log.isDebugEnabled()) { log.debug("populateModule: Building module description for: " + module.getName()); } // Process service description OMElement descriptionElement = moduleElement.getFirstChildWithName(new QName(TAG_DESCRIPTION)); if (descriptionElement != null) { OMElement descriptionValue = descriptionElement.getFirstElement(); if (descriptionValue != null) { StringWriter writer = new StringWriter(); descriptionValue.build(); descriptionValue.serialize(writer); writer.flush(); module.setModuleDescription(writer.toString()); } else { module.setModuleDescription(descriptionElement.getText()); } } else { module.setModuleDescription("module description not found"); } // Processing Dynamic Phase Iterator phaseItr = moduleElement.getChildrenWithName(new QName(TAG_PHASE)); processModulePhase(phaseItr); // setting the PolicyInclude // processing <wsp:Policy> .. </..> elements Iterator policyElements = moduleElement.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY)); if (policyElements != null && policyElements.hasNext()) { processPolicyElements(policyElements, module.getPolicySubject()); } // processing <wsp:PolicyReference> .. </..> elements Iterator policyRefElements = moduleElement .getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY_REF)); if (policyRefElements != null && policyRefElements.hasNext()) { processPolicyRefElements(policyRefElements, module.getPolicySubject()); } // process flows (case-insensitive) Iterator flows = moduleElement.getChildElements(); while (flows.hasNext()) { OMElement flowElement = (OMElement) flows.next(); final String flowName = flowElement.getLocalName(); if (flowName.compareToIgnoreCase(TAG_FLOW_IN) == 0) { module.setInFlow(processFlow(flowElement, module)); } else if (flowName.compareToIgnoreCase(TAG_FLOW_OUT) == 0) { module.setOutFlow(processFlow(flowElement, module)); } else if (flowName.compareToIgnoreCase(TAG_FLOW_IN_FAULT) == 0) { module.setFaultInFlow(processFlow(flowElement, module)); } else if (flowName.compareToIgnoreCase(TAG_FLOW_OUT_FAULT) == 0) { module.setFaultOutFlow(processFlow(flowElement, module)); } } OMElement supportedPolicyNamespaces = moduleElement .getFirstChildWithName(new QName(TAG_SUPPORTED_POLICY_NAMESPACES)); if (supportedPolicyNamespaces != null) { module.setSupportedPolicyNamespaces(processSupportedPolicyNamespaces(supportedPolicyNamespaces)); } /* * Module description should contain a list of QName of the assertions that are local to the system. * These assertions are not exposed to the outside. */ OMElement localPolicyAssertionElement = moduleElement .getFirstChildWithName(new QName("local-policy-assertions")); if (localPolicyAssertionElement != null) { module.setLocalPolicyAssertions(getLocalPolicyAssertionNames(localPolicyAssertionElement)); } // processing Operations Iterator op_itr = moduleElement.getChildrenWithName(new QName(TAG_OPERATION)); ArrayList<AxisOperation> operations = processOperations(op_itr); for (AxisOperation op : operations) { module.addOperation(op); } if (log.isDebugEnabled()) { log.debug("populateModule: Done building module description"); } } catch (XMLStreamException e) { throw new DeploymentException(e); } catch (AxisFault e) { throw new DeploymentException(e); } }
From source file:org.qi4j.entitystore.sql.SQLEntityStoreMixin.java
public StateCommitter applyChanges(final EntityStoreUnitOfWork unitofwork, final Iterable<EntityState> states) { return new StateCommitter() { public void commit() { Connection connection = null; PreparedStatement insertPS = null; PreparedStatement updatePS = null; PreparedStatement removePS = null; try { connection = database.getConnection(); insertPS = database.prepareInsertEntityStatement(connection); updatePS = database.prepareUpdateEntityStatement(connection); removePS = database.prepareRemoveEntityStatement(connection); for (EntityState state : states) { EntityStatus status = state.status(); DefaultEntityState defState = ((SQLEntityState) state).getDefaultEntityState(); Long entityPK = ((SQLEntityState) state).getEntityPK(); if (EntityStatus.REMOVED.equals(status)) { database.populateRemoveEntityStatement(removePS, entityPK, state.identity()); removePS.addBatch(); } else { StringWriter writer = new StringWriter(); writeEntityState(defState, writer, unitofwork.identity()); writer.flush(); if (EntityStatus.UPDATED.equals(status)) { Long entityOptimisticLock = ((SQLEntityState) state).getEntityOptimisticLock(); database.populateUpdateEntityStatement(updatePS, entityPK, entityOptimisticLock, defState.identity(), writer.toString(), unitofwork.currentTime()); updatePS.addBatch(); } else if (EntityStatus.NEW.equals(status)) { database.populateInsertEntityStatement(insertPS, entityPK, defState.identity(), writer.toString(), unitofwork.currentTime()); insertPS.addBatch(); }//from ww w . j a v a 2 s .c o m } } removePS.executeBatch(); insertPS.executeBatch(); updatePS.executeBatch(); connection.commit(); } catch (SQLException sqle) { SQLUtil.rollbackQuietly(connection); if (LOGGER.isDebugEnabled()) { StringWriter sb = new StringWriter(); sb.append( "SQLException during commit, logging nested exceptions before throwing EntityStoreException:\n"); SQLException e = sqle; while (e != null) { e.printStackTrace(new PrintWriter(sb, true)); e = e.getNextException(); } LOGGER.debug(sb.toString()); } throw new EntityStoreException(sqle); } catch (RuntimeException re) { SQLUtil.rollbackQuietly(connection); throw new EntityStoreException(re); } finally { SQLUtil.closeQuietly(insertPS); SQLUtil.closeQuietly(updatePS); SQLUtil.closeQuietly(removePS); SQLUtil.closeQuietly(connection); } } public void cancel() { } }; }