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();
}
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();
}
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;
}
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);
}
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();
}
Aggregations