Search in sources :

Example 81 with CharArrayWriter

use of java.io.CharArrayWriter in project OpenGrok by OpenGrok.

the class TroffAnalyzerTest method setUpBeforeClass.

/**
     * Test method for {@link org.opensolaris.opengrok.analysis.document
     * .TroffAnalyzer#TroffAnalyzer(org.opensolaris.opengrok.analysis.FileAnalyzerFactory)}.
     *
     * @throws java.lang.Exception
     */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    factory = new TroffAnalyzerFactory();
    assertNotNull(factory);
    analyzer = new TroffAnalyzer(factory);
    assertNotNull(analyzer);
    repository = new TestRepository();
    repository.create(TroffAnalyzerTest.class.getResourceAsStream("/org/opensolaris/opengrok/index/source.zip"));
    String file = System.getProperty("opengrok.test.troff.doc", repository.getSourceRoot() + "/document/foobar.1");
    File f = new File(file);
    if (!(f.canRead() && f.isFile())) {
        fail("troff testfile " + f + " not found");
    }
    CharArrayWriter w = new CharArrayWriter((int) f.length());
    Util.dump(w, f, false);
    content = w.toString();
}
Also used : TestRepository(org.opensolaris.opengrok.util.TestRepository) File(java.io.File) CharArrayWriter(java.io.CharArrayWriter) BeforeClass(org.junit.BeforeClass)

Example 82 with CharArrayWriter

use of java.io.CharArrayWriter in project androidannotations by androidannotations.

the class ErrorHelper method elementFullString.

private String elementFullString(ProcessingEnvironment processingEnv, Element element) {
    Elements elementUtils = processingEnv.getElementUtils();
    CharArrayWriter writer = new CharArrayWriter();
    elementUtils.printElements(writer, element);
    return writer.toString();
}
Also used : Elements(javax.lang.model.util.Elements) CharArrayWriter(java.io.CharArrayWriter)

Example 83 with CharArrayWriter

use of java.io.CharArrayWriter in project nhin-d by DirectProject.

the class XslConversion method run.

/**
     * Perform the XSL conversion using the provided map file and message.
     * 
     * @param mapFile
     *            The map file.
     * @param message
     *            The message.
     * @return an XSL conversion.
     * @throws Exception
     */
public String run(String mapFile, String message) throws Exception {
    long start = System.currentTimeMillis();
    String retXml = "";
    Transformer transformer = null;
    try {
        if (conversions.containsKey(mapFile)) {
            Templates temp = conversions.get(mapFile);
            transformer = temp.newTransformer();
            LOGGER.info("From xsl cache");
        } else {
            synchronized (conversions) {
                if (!conversions.containsKey(mapFile)) {
                    /*
                         * Use the static TransformerFactory.newInstance()
                         * method to instantiate a TransformerFactory. The
                         * javax.xml.transform.TransformerFactory system
                         * property setting determines the actual class to
                         * instantiate --
                         * org.apache.xalan.transformer.TransformerImpl.
                         */
                    TransformerFactory tFactory = TransformerFactory.newInstance();
                    /*
                         * Use the TransformerFactory to instantiate a Template
                         * that is thread safe for use in generating Transfomers
                         */
                    InputStream is = this.getClass().getClassLoader().getResourceAsStream(mapFile);
                    if (is == null) {
                        LOGGER.info("Mapfile did not read " + mapFile);
                    }
                    Templates temp = tFactory.newTemplates(new StreamSource(is));
                    transformer = temp.newTransformer();
                    conversions.put(mapFile, temp);
                }
            }
        }
        CharArrayWriter to = new CharArrayWriter();
        transformer.transform(new StreamSource(new CharArrayReader(message.toCharArray())), new StreamResult(to));
        retXml = to.toString();
    } catch (TransformerConfigurationException e) {
        LOGGER.error("Exception occured during XSL conversion", e);
        throw e;
    } catch (TransformerException e) {
        LOGGER.error("Exception occured during XSL conversion", e);
        throw e;
    }
    if (LOGGER.isInfoEnabled()) {
        long elapse = System.currentTimeMillis() - start;
        LOGGER.info("Started at " + new Timestamp(start).toString());
        LOGGER.info("Elapsed conversion time was " + elapse + "ms");
    }
    return retXml;
}
Also used : Transformer(javax.xml.transform.Transformer) TransformerFactory(javax.xml.transform.TransformerFactory) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Templates(javax.xml.transform.Templates) Timestamp(java.sql.Timestamp) CharArrayWriter(java.io.CharArrayWriter) CharArrayReader(java.io.CharArrayReader) TransformerException(javax.xml.transform.TransformerException)

Example 84 with CharArrayWriter

use of java.io.CharArrayWriter in project intellij-community by JetBrains.

the class Connection method authenticateWithPublicKey.

/**
	 * A convenience wrapper function which reads in a private key (PEM format,
	 * either DSA or RSA) and then calls
	 * <code>authenticateWithPublicKey(String, char[], String)</code>.
	 * <p>
	 * NOTE PUTTY USERS: Event though your key file may start with
	 * "-----BEGIN..." it is not in the expected format. You have to convert it
	 * to the OpenSSH key format by using the "puttygen" tool (can be downloaded
	 * from the Putty website). Simply load your key and then use the
	 * "Conversions/Export OpenSSH key" functionality to get a proper PEM file.
	 * 
	 * @param user
	 *            A <code>String</code> holding the username.
	 * @param pemFile
	 *            A <code>File</code> object pointing to a file containing a
	 *            DSA or RSA private key of the user in OpenSSH key format (PEM,
	 *            you can't miss the "-----BEGIN DSA PRIVATE KEY-----" or
	 *            "-----BEGIN RSA PRIVATE KEY-----" tag).
	 * @param password
	 *            If the PEM file is encrypted then you must specify the
	 *            password. Otherwise, this argument will be ignored and can be
	 *            set to <code>null</code>.
	 * 
	 * @return whether the connection is now authenticated.
	 * @throws IOException
	 */
public synchronized boolean authenticateWithPublicKey(String user, File pemFile, String password) throws IOException {
    if (pemFile == null)
        throw new IllegalArgumentException("pemFile argument is null");
    char[] buff = new char[256];
    CharArrayWriter cw = new CharArrayWriter();
    FileReader fr = new FileReader(pemFile);
    while (true) {
        int len = fr.read(buff);
        if (len < 0)
            break;
        cw.write(buff, 0, len);
    }
    fr.close();
    return authenticateWithPublicKey(user, cw.toCharArray(), password);
}
Also used : FileReader(java.io.FileReader) CharArrayWriter(java.io.CharArrayWriter)

Example 85 with CharArrayWriter

use of java.io.CharArrayWriter in project XobotOS by xamarin.

the class MobileDataStateTracker method toString.

@Override
public String toString() {
    final CharArrayWriter writer = new CharArrayWriter();
    final PrintWriter pw = new PrintWriter(writer);
    pw.print("Mobile data state: ");
    pw.println(mMobileDataState);
    pw.print("Data enabled: user=");
    pw.print(mUserDataEnabled);
    pw.print(", policy=");
    pw.println(mPolicyDataEnabled);
    return writer.toString();
}
Also used : CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter)

Aggregations

CharArrayWriter (java.io.CharArrayWriter)116 PrintWriter (java.io.PrintWriter)28 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)21 IOException (java.io.IOException)16 BufferedReader (java.io.BufferedReader)7 ArrayList (java.util.ArrayList)7 CharArrayReader (java.io.CharArrayReader)6 Test (org.junit.Test)5 File (java.io.File)4 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 HashMap (java.util.HashMap)4 FeatureVector (com.airbnb.aerosolve.core.FeatureVector)3 ModelHeader (com.airbnb.aerosolve.core.ModelHeader)3 ModelRecord (com.airbnb.aerosolve.core.ModelRecord)3 BufferedWriter (java.io.BufferedWriter)3 InputStreamReader (java.io.InputStreamReader)3 StreamResult (javax.xml.transform.stream.StreamResult)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2