Example usage for java.io Writer write

List of usage examples for java.io Writer write

Introduction

In this page you can find the example usage for java.io Writer write.

Prototype

public void write(String str) throws IOException 

Source Link

Document

Writes a string.

Usage

From source file:kr.okplace.job.support.SummaryFooterCallback.java

public void writeFooter(Writer writer) throws IOException {
    writer.write("footer - number of items written: " + stepExecution.getWriteCount());
}

From source file:com.adobe.communities.ugc.migration.export.UGCExportHelper.java

public static void extractAttachment(final Writer ioWriter, final JSONWriter writer, final Resource node)
        throws JSONException {
    Resource contentNode = node.getChild("jcr:content");
    if (contentNode == null) {
        writer.key(ContentTypeDefinitions.LABEL_ERROR);
        writer.value("provided resource was not an attachment - no content node");
        return;//from  ww  w  .  ja v  a  2s  . c  om
    }
    ValueMap content = contentNode.getValueMap();
    if (!content.containsKey("jcr:mimeType") || !content.containsKey("jcr:data")) {
        writer.key(ContentTypeDefinitions.LABEL_ERROR);
        writer.value("provided resource was not an attachment - content node contained no attachment data");
        return;
    }
    writer.key("filename");
    writer.value(node.getName());
    writer.key("jcr:mimeType");
    writer.value(content.get("jcr:mimeType"));

    try {
        ioWriter.write(",\"jcr:data\":\"");
        final InputStream data = (InputStream) content.get("jcr:data");
        byte[] byteData = new byte[DATA_ENCODING_CHUNK_SIZE];
        int read = 0;
        while (read != -1) {
            read = data.read(byteData);
            if (read > 0 && read < DATA_ENCODING_CHUNK_SIZE) {
                // make a right-size container for the byte data actually read
                byte[] byteArray = new byte[read];
                System.arraycopy(byteData, 0, byteArray, 0, read);
                byte[] encodedBytes = Base64.encodeBase64(byteArray);
                ioWriter.write(new String(encodedBytes));
            } else if (read == DATA_ENCODING_CHUNK_SIZE) {
                byte[] encodedBytes = Base64.encodeBase64(byteData);
                ioWriter.write(new String(encodedBytes));
            }
        }
        ioWriter.write("\"");
    } catch (IOException e) {
        writer.key(ContentTypeDefinitions.LABEL_ERROR);
        writer.value("IOException while getting attachment: " + e.getMessage());
    }
}

From source file:net.sf.taverna.cagrid.activity.CaGridActivity.java

/**
 * Load the trusted caGrid CAs' certificates and store them in 
 * the Truststore and in a special folder (inside Taverna's security 
 * conf folder) so that globus can look them up as well.
 *//* www . java2  s.c  o m*/
private static void loadCaGridCAsCertificates() {

    // If not already done, import the caGrid Trusted CAs' certificates into Taverna's truststore
    // Get the location of Taverna's security configuration directory
    File secConfigDirectory = CMUtil.getSecurityConfigurationDirectory();
    File caGridSecConfigDirectory = new File(secConfigDirectory, "cagrid");
    caGridSecConfigDirectory.mkdirs();
    // Tructes CAs folder
    File trustedCertsDirectory = new File(caGridSecConfigDirectory, "trusted-certificates");
    trustedCertsDirectory.mkdirs();

    // Set the system property read by Globus to determine the location 
    // of the folder containing the caGrid trusted CAs' certificates 
    System.setProperty("X509_CERT_DIR", trustedCertsDirectory.getAbsolutePath());

    // Get the file which existence implies that caGrid trusted CAs have been loaded
    File caCertsLoadedFile = new File(caGridSecConfigDirectory, "trustedCAsLoaded.txt");

    if (!caCertsLoadedFile.exists() || System.getenv("TWS_USER_PROXY") != null) {
        logger.info("caGrid plugin is loading trusted certificates \n of caGrid CAs into Credential Manager.");

        if (System.getenv("TWS_USER_PROXY") == null) {
            JOptionPane.showMessageDialog(null,
                    "caGrid plugin is loading trusted certificates \n of caGrid CAs into Credential Manager.",
                    "CaGrid plugin message", JOptionPane.INFORMATION_MESSAGE);
        }
        List<String> certificateResources = new ArrayList<String>();
        certificateResources.add("1c3f2ca8.0");
        certificateResources.add("62f4fd66.0");
        certificateResources.add("68907d53.0");
        certificateResources.add("8e3e7e54.0");
        certificateResources.add("d1b603c3.0");
        certificateResources.add("ed524cf5.0");
        certificateResources.add("0ad31d10.0");
        certificateResources.add("17e36bb5.0");
        certificateResources.add("f3b3491b.0");
        certificateResources.add("d0b62510.0");//to be replaced by its CA cert

        CredentialManager cm = null;
        try {
            //TODO something wrong here, needs correction
            cm = CredentialManager.getInstance();

        } catch (CMException cmex) {
            // We are in deep trouble here - something's wrong with Credential Manager
            String exMessage = "Failed to instantiate Credential Manager - cannot load caGrid CAs' certificates.";
            JOptionPane.showMessageDialog(null, exMessage, "CaGrid plugin message", JOptionPane.ERROR_MESSAGE);
            cmex.printStackTrace();
            logger.error(exMessage);
            return;
        }

        for (String certificate : certificateResources) {
            InputStream certStream = null;
            try {
                String certificateResourcePath = "/trusted-certificates/" + certificate;
                certStream = CaGridActivity.class.getResourceAsStream(certificateResourcePath);
                CertificateFactory cf = CertificateFactory.getInstance("X.509");
                // The following should be able to load PKCS #7 certificate chain files
                // as well as ASN.1 DER or PEM-encoded (sequences of) certificates
                Collection<? extends Certificate> chain = cf.generateCertificates(certStream);
                certStream.close();
                // Use only the first cert in the chain - we know there will be only one inside 
                X509Certificate cert = (X509Certificate) chain.iterator().next();
                // Save to Credential Manager's Truststore
                cm.saveTrustedCertificate(cert);
                // Save to the trusted-certificates directory inside cagrid security conf directory
                File certificateFile = new File(trustedCertsDirectory, certificate);
                InputStream certStreamNew = null;
                BufferedOutputStream fOut = null;
                try {
                    // Reload the certificate resource
                    certStreamNew = CaGridActivity.class.getResourceAsStream(certificateResourcePath);
                    fOut = new BufferedOutputStream(new FileOutputStream(certificateFile));
                    IOUtils.copy(certStreamNew, fOut);
                } catch (Exception ex) {
                    String exMessage = "Failed to save caGrid CA's certificate " + certificate
                            + " to cagrid security folder " + certificateFile + " for globus.";
                    logger.error(exMessage, ex);
                } finally {
                    if (fOut != null) {
                        try {
                            fOut.close();
                        } catch (Exception ex) {
                            logger.error("Can't close certificate resource " + certificateFile, ex);
                        }
                    }
                    if (certStreamNew != null) {
                        try {
                            certStreamNew.close();
                        } catch (Exception ex) {
                            logger.error("Can't close certificate resource " + certificate, ex);
                        }
                    }
                }
            } catch (Exception ex) {
                String exMessage = "Failed to load or save caGrid CA's certificate " + certificate
                        + " to Truststore.";
                logger.error(exMessage, ex);
            }
        }
        Writer out = null;
        try {
            out = new BufferedWriter(new FileWriter(caCertsLoadedFile));
            out.write("true"); // just write anything to the file
        } catch (IOException e) {
            // ignore
        }
        if (out != null) {
            try {
                out.close();
            } catch (Exception ex) {
                // ignore
            }
        }
    }
}

From source file:kr.okplace.job.support.HeaderCopyCallback.java

public void writeHeader(Writer writer) throws IOException {
    writer.write("header from input: " + header);

}

From source file:fr.francetelecom.callback.ItemReaderFooter.java

@Override
public void writeFooter(Writer writer) throws IOException {
    writer.write("Total Amount Processed: " + totalAmount);
}

From source file:de.langmi.spring.batch.examples.playground.file.footer.callback.CustomWriter.java

@Override
public void writeFooter(Writer writer) throws IOException {
    writer.write("count:" + count);
}

From source file:net.groupbuy.template.directive.CurrentMemberDirective.java

@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    Member currentMember = memberService.getCurrent();
    if (body != null) {
        setLocalVariable(VARIABLE_NAME, currentMember, env, body);
    } else {/*from w  w  w.  j  a  v a2 s  . c o m*/
        if (currentMember != null) {
            Writer out = env.getOut();
            out.write(currentMember.getUsername());
        }
    }
}

From source file:info.magnolia.cms.gui.dialog.DialogTab.java

public void drawHtmlPostSubs(Writer out) throws IOException {
    out.write("</table>"); //$NON-NLS-1$
    out.write("</td></tr></table></div>"); //$NON-NLS-1$
}

From source file:hu.qgears.xtextdoc.util.EscapeString.java

/**
 * <p>//from  w w w .j  ava 2 s.  c om
 * Worker method for the {@link #escapeJavaScript(String)} method.
 * </p>
 * 
 * @param out
 *            write to receieve the escaped string
 * @param str
 *            String to escape values in, may be null
 * @param escapeSingleQuote
 *            escapes single quotes if <code>true</code>
 * @throws IOException
 *             if an IOException occurs
 */
private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote)
        throws IOException {
    if (out == null) {
        throw new IllegalArgumentException("The Writer must not be null");
    }
    if (str == null) {
        return;
    }
    int sz;
    sz = str.length();
    for (int i = 0; i < sz; i++) {
        char ch = str.charAt(i);

        // handle unicode
        if (ch > 0xfff) {
            out.write("\\u" + hex(ch));
        } else if (ch > 0xff) {
            out.write("\\u0" + hex(ch));
        } else if (ch > 0x7f) {
            out.write("\\u00" + hex(ch));
        } else if (ch < 32) {
            switch (ch) {
            case '\b':
                out.write('\\');
                out.write('b');
                break;
            case '\n':
                out.write('\\');
                out.write('n');
                break;
            case '\t':
                out.write('\\');
                out.write('t');
                break;
            case '\f':
                out.write('\\');
                out.write('f');
                break;
            case '\r':
                out.write('\\');
                out.write('r');
                break;
            default:
                if (ch > 0xf) {
                    out.write("\\u00" + hex(ch));
                } else {
                    out.write("\\u000" + hex(ch));
                }
                break;
            }
        } else {
            switch (ch) {
            case '\'':
                if (escapeSingleQuote) {
                    out.write('\\');
                }
                out.write('\'');
                break;
            case '"':
                out.write('\\');
                out.write('"');
                break;
            case '\\':
                out.write('\\');
                out.write('\\');
                break;
            // Fixed by SA
            // case '/':
            // out.write('\\');
            // out.write('/');
            // break;
            default:
                out.write(ch);
                break;
            }
        }
    }
}

From source file:cn.vlabs.umt.ui.tags.RequestCount.java

public int doStartTag() throws JspException {
    BeanFactory factory = (BeanFactory) pageContext.getServletContext()
            .getAttribute(Attributes.APPLICATION_CONTEXT_KEY);
    RequestService us = (RequestService) factory.getBean("RequestService");
    int count = us.getRequestCount(UserRequest.INIT);
    try {/*  w w  w  .  j av a2  s  .com*/
        Writer writer = pageContext.getOut();
        writer.write(Integer.toString(count));
        writer.flush();
    } catch (IOException e) {
        throw new JspException(e);
    }
    return SKIP_BODY;
}