Example usage for java.io StringReader StringReader

List of usage examples for java.io StringReader StringReader

Introduction

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

Prototype

public StringReader(String s) 

Source Link

Document

Creates a new string reader.

Usage

From source file:com.jaeksoft.searchlib.util.PdfCrack.java

public final static String findPassword(String pdfCrackCommandLine, File file)
        throws ExecuteException, IOException {
    ByteArrayOutputStream out = null;
    ByteArrayOutputStream err = null;
    BufferedReader br = null;//from   w  ww.j a  va 2s.c o m
    try {
        out = new ByteArrayOutputStream();
        err = new ByteArrayOutputStream();
        ExecuteUtils.command(null, pdfCrackCommandLine, null, false, out, err, 3600000L, "-f",
                StringUtils.fastConcat("\"", file.getAbsolutePath(), "\""));
        br = new BufferedReader(new StringReader(out.toString()));
        String line;
        int start = FOUND_USER_PASSWORD.length();
        while ((line = br.readLine()) != null) {
            if (line.startsWith(FOUND_USER_PASSWORD)) {
                int end = line.length() - 1;
                return end == start ? "" : line.substring(start, end);
            }
        }
        return null;
    } finally {
        IOUtils.close(out, err, br);
    }
}

From source file:Main.java

public static Schema getSchema(String schemaString) {
    Schema schema = null;/* w  w  w  .ja v a 2 s . c  o m*/
    try {
        if (schemaString != null) {
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            StreamSource ss = new StreamSource();
            ss.setReader(new StringReader(schemaString));
            schema = sf.newSchema(ss);
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to create schemma from string: " + schemaString, e);
    }
    return schema;
}

From source file:Main.java

/** Returns a text where all line separator are \n
 *
 * @return the normalized text// www  .  j  a  va 2 s  .  c  o  m
 */

public static String getNormalizedText(String text) {
    StringBuffer normalizedText = new StringBuffer();
    BufferedReader reader = new BufferedReader(new StringReader(text));
    try {
        String line;
        while ((line = reader.readLine()) != null) {
            normalizedText.append(line);
            normalizedText.append("\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return normalizedText.toString();
}

From source file:com.trusolve.ant.filters.YamlToJsonFilter.java

public static Reader readDocument(Reader in) throws JsonProcessingException, IOException {
    YamlToJson yj = new YamlToJson();
    String doc = yj.convertToString(in);
    return new StringReader(doc);
}

From source file:net.sf.janos.model.xml.ResultParser.java

/**
 * @param xml/*from   www  .j ava2  s  .  com*/
 * @return a list of Entrys from the given xml string.
 * @throws IOException
 * @throws SAXException
 */
public static List<Entry> getEntriesFromStringResult(String xml) throws SAXException {
    XMLReader reader = XMLReaderFactory.createXMLReader();
    EntryHandler handler = new EntryHandler();
    reader.setContentHandler(handler);
    try {
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        // This should never happen - we're not performing I/O!
        LOG.error("Could not parse entries: ", e);
    }
    return handler.getArtists();
}

From source file:Main.java

/**
 * Transform XML to JSON/*from   www .  j  av  a  2s  .c om*/
 *
 * @param xml
 * @return
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 */
public static String toJson(String xml) throws ParserConfigurationException, SAXException, IOException {
    JsonObject rootJson = new JsonObject();
    DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = dBuilder.parse(new InputSource(new StringReader(xml)));
    if (doc.hasChildNodes()) {
        traverseNode(doc, rootJson, null);
    }
    Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
    String json = gson.toJson(rootJson);

    return json;
}

From source file:Main.java

/**
 * @param parent//  w w w. j av a2 s .com
 *          node to add fragment to
 * @param fragment
 *          a well formed XML fragment
 * @throws ParserConfigurationException 
 */
public static void appendXmlFragment(Node parent, String fragment)
        throws IOException, SAXException, ParserConfigurationException {

    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true);
    DocumentBuilder docBuilder = domFactory.newDocumentBuilder();
    Document doc = parent.getOwnerDocument();

    Node fragmentNode = docBuilder.parse(new InputSource(new StringReader(fragment))).getDocumentElement();

    fragmentNode = doc.importNode(fragmentNode, true);

    parent.appendChild(fragmentNode);
}

From source file:Main.java

public static String indent(String xml) throws TransformerException {
    xml = removeBOM(xml);//w w w.  j  a  v  a 2  s.  c  om
    if (xml != null)
        xml = xml.trim();
    if ((xml == null) || (xml.length() == 0)) {
        throw new TransformerException("Empty XML.");
    }
    StringWriter result = new StringWriter();
    transform(new StreamSource(new StringReader(xml)), new StreamResult(result), true);
    return checkResult(result, true);
}

From source file:edu.harvard.i2b2.analysis.queryClient.QueryClient.java

public static OMElement getQueryPayLoad(String XMLstr) throws Exception {
    StringReader strReader = new StringReader(XMLstr);
    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader reader = xif.createXMLStreamReader(strReader);

    StAXOMBuilder builder = new StAXOMBuilder(reader);
    OMElement lineItem = builder.getDocumentElement();
    // System.out.println("Line item string " + lineItem.toString());
    return lineItem;
}

From source file:com.shmsoft.dmass.print.Html2Pdf.java

public static void htmlContent2Pdf(String inputContent, String outputFile) throws Exception {
    StringReader htmlReader = new StringReader(inputContent);
    convertHtml2Pdf(htmlReader, outputFile);
}