Example usage for org.apache.commons.io.input ReaderInputStream ReaderInputStream

List of usage examples for org.apache.commons.io.input ReaderInputStream ReaderInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io.input ReaderInputStream ReaderInputStream.

Prototype

public ReaderInputStream(Reader reader, String charsetName) 

Source Link

Document

Construct a new ReaderInputStream with a default input buffer size of 1024 characters.

Usage

From source file:com.ibm.jaggr.core.util.CopyUtil.java

public static void copy(Reader reader, OutputStream out) throws IOException {
    InputStream in = new ReaderInputStream(reader, "UTF-8"); //$NON-NLS-1$
    try {/*  w  w  w .  j a v a2s. c o m*/
        IOUtils.copy(in, out);
    } finally {
        try {
            in.close();
        } catch (Exception ignore) {
        }
        try {
            out.close();
        } catch (Exception ignore) {
        }
    }
}

From source file:com.vitesify.languidmpd.streams.TestMPDStreamProcessor.java

@Test
public void test_send_single_command() throws IOException {
    InputStream is = new ReaderInputStream(new StringReader("OK\nOK\nNOT OK\nOK"), Charset.forName("UTF-8"));
    OutputStream os = new NullOutputStream();
    MPDStreamProcesser mpdsp = new MPDStreamProcesser(is, os);

    Set<String> s = Collections.emptySet();
    assertTrue(mpdsp.send_command(Message.STATUS, s));
    assertTrue(mpdsp.last_command_succeeded());

    assertTrue(mpdsp.get_return_code().endsWith("NOT OK\n"));
}

From source file:com.github.dozermapper.core.builder.xml.InputStreamLSInput.java

@Override
public InputStream getByteStream() {
    return new ReaderInputStream(characterStream, getEncoding());
}

From source file:name.martingeisse.webide.features.java.compiler.memfile.MemoryStringFileObject.java

@Override
public InputStream openInputStream() throws IOException {
    return new ReaderInputStream(openReader(true), "utf-8");
}

From source file:io.cloudslang.content.database.services.SQLQueryLobService.java

public static boolean executeSqlQueryLob(SQLInputs sqlInputs) throws Exception {
    if (StringUtils.isEmpty(sqlInputs.getSqlCommand())) {
        throw new Exception("command input is empty.");
    }/* w  ww  .  j a  v a  2s.  c  o  m*/
    boolean isLOB = false;
    ConnectionService connectionService = new ConnectionService();
    try (final Connection connection = connectionService.setUpConnection(sqlInputs)) {

        StringBuilder strColumns = new StringBuilder(sqlInputs.getStrColumns());

        connection.setReadOnly(true);
        Statement statement = connection.createStatement(sqlInputs.getResultSetType(),
                sqlInputs.getResultSetConcurrency());
        statement.setQueryTimeout(sqlInputs.getTimeout());

        ResultSet results = statement.executeQuery(sqlInputs.getSqlCommand());
        ResultSetMetaData mtd = results.getMetaData();
        int iNumCols = mtd.getColumnCount();
        for (int i = 1; i <= iNumCols; i++) {
            if (i > 1)
                strColumns.append(sqlInputs.getStrDelim());
            strColumns.append(mtd.getColumnLabel(i));
        }
        sqlInputs.setStrColumns(strColumns.toString());
        int nr = -1;
        while (results.next()) {
            nr++;
            final StringBuilder strRowHolder = new StringBuilder();
            for (int i = 1; i <= iNumCols; i++) {
                if (i > 1)
                    strRowHolder.append(sqlInputs.getStrDelim());
                Object columnObject = results.getObject(i);
                if (columnObject != null) {
                    String value;
                    if (columnObject instanceof java.sql.Clob) {
                        isLOB = true;
                        final File tmpFile = File.createTempFile("CLOB_" + mtd.getColumnLabel(i), ".txt");

                        copyInputStreamToFile(
                                new ReaderInputStream(results.getCharacterStream(i), StandardCharsets.UTF_8),
                                tmpFile);

                        if (sqlInputs.getLRowsFiles().size() == nr) {
                            sqlInputs.getLRowsFiles().add(nr, new ArrayList<String>());
                            sqlInputs.getLRowsNames().add(nr, new ArrayList<String>());
                        }
                        sqlInputs.getLRowsFiles().get(nr).add(tmpFile.getAbsolutePath());
                        sqlInputs.getLRowsNames().get(nr).add(mtd.getColumnLabel(i));
                        value = "(CLOB)...";

                    } else {
                        value = results.getString(i);
                        if (sqlInputs.isNetcool())
                            value = SQLUtils.processNullTerminatedString(value);
                    }
                    strRowHolder.append(value);
                } else
                    strRowHolder.append("null");
            }
            sqlInputs.getLRows().add(strRowHolder.toString());
        }
    }

    return isLOB;
}

From source file:cz.muni.fi.mir.mathmlunificator.AbstractXMLTransformationTest.java

protected InputStream getTestResource(String testFile) {
    String resourceFile = this.getClass().getSimpleName() + "/" + testFile;
    InputStream rs = this.getClass().getResourceAsStream(resourceFile);
    return new ReaderInputStream(new InputStreamReader(rs, StandardCharsets.UTF_8), StandardCharsets.UTF_8);
}

From source file:com.evolveum.midpoint.tools.ninja.ImportObjects.java

public boolean execute() {
    System.out.println("Starting objects import.");

    File objects = new File(filePath);
    if (!objects.exists() || !objects.canRead()) {
        System.out.println(//from  w  ww  . j a va 2  s. c  om
                "XML file with objects '" + objects.getAbsolutePath() + "' doesn't exist or can't be read.");
        return false;
    }

    InputStream input = null;
    ClassPathXmlApplicationContext context = null;
    try {
        System.out.println("Loading spring contexts.");
        context = new ClassPathXmlApplicationContext(CONTEXTS);

        InputStreamReader reader = new InputStreamReader(new FileInputStream(objects), "utf-8");
        input = new ReaderInputStream(reader, reader.getEncoding());

        final RepositoryService repository = context.getBean("repositoryService", RepositoryService.class);
        PrismContext prismContext = context.getBean(PrismContext.class);

        EventHandler handler = new EventHandler() {

            @Override
            public EventResult preMarshall(Element objectElement, Node postValidationTree,
                    OperationResult objectResult) {
                return EventResult.cont();
            }

            @Override
            public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement,
                    OperationResult objectResult) {
                try {
                    String displayName = getDisplayName(object);
                    System.out.println("Importing object " + displayName);

                    repository.addObject((PrismObject<ObjectType>) object, null, objectResult);
                } catch (Exception ex) {
                    objectResult.recordFatalError("Unexpected problem: " + ex.getMessage(), ex);

                    System.out.println("Exception occurred during import, reason: " + ex.getMessage());
                    ex.printStackTrace();
                }

                objectResult.recordSuccessIfUnknown();
                if (objectResult.isAcceptable()) {
                    // Continue import
                    return EventResult.cont();
                } else {
                    return EventResult.skipObject(objectResult.getMessage());
                }
            }

            @Override
            public void handleGlobalError(OperationResult currentResult) {
            }
        };
        Validator validator = new Validator(prismContext, handler);
        validator.setVerbose(true);
        validator.setValidateSchema(validateSchema);

        OperationResult result = new OperationResult("Import objeccts");
        validator.validate(input, result, OperationConstants.IMPORT_OBJECT);

        result.recomputeStatus();
        if (!result.isSuccess()) {
            System.out.println("Operation result was not success, dumping result.\n" + result.debugDump(3));
        }
    } catch (Exception ex) {
        System.out.println("Exception occurred during import task, reason: " + ex.getMessage());
        ex.printStackTrace();
    } finally {
        IOUtils.closeQuietly(input);
        destroyContext(context);
    }

    System.out.println("Objects import finished.");
    return true;
}

From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java

public static Resource readFromString(String input) throws IOException {
    StringReader stringReader = new StringReader(input);
    ReaderInputStream is = new ReaderInputStream(stringReader, Charset.forName("UTF-8"));
    Resource resource = readFromStream(is);
    is.close();//from   ww  w .ja va 2  s  . c o  m
    return resource;
}

From source file:com.ppcxy.cyfm.showcase.demos.utilities.io.IODemo.java

@Test
public void workWithStream() {
    InputStream in = null;/*  w ww  .j  a  va 2s .  c  o m*/
    try {
        String content = "Stream testing";

        // String - > InputStream.
        in = IOUtils.toInputStream(content, "UTF-8");

        // String - > OutputStream
        System.out.println("String to OutputStram:");
        IOUtils.write(content, System.out, "UTF-8");

        // //////////////////
        // InputStream/Reader -> String
        System.out.println("\nInputStram to String:");
        System.out.println(IOUtils.toString(in, "UTF-8"));

        // InputStream/Reader -> OutputStream/Writer ???.
        InputStream in2 = IOUtils.toInputStream(content); // ?inputSteam
        System.out.println("InputStream to OutputStream:");
        IOUtils.copy(in2, System.out);

        // /////////////////
        // InputStream ->Reader
        InputStreamReader reader = new InputStreamReader(in, Charsets.UTF_8);
        // Reader->InputStream
        ReaderInputStream in3 = new ReaderInputStream(reader, Charsets.UTF_8);

        // OutputStream ->Writer
        OutputStreamWriter writer = new OutputStreamWriter(System.out, Charsets.UTF_8);
        // Writer->OutputStream
        WriterOutputStream out2 = new WriterOutputStream(writer, Charsets.UTF_8);

        // ////////////////////
        // WriterString.
        StringWriter sw = new StringWriter();
        sw.write("I am String writer");
        System.out.println("\nCollect writer content:");
        System.out.println(sw.toString());

    } catch (IOException e) {
        Exceptions.unchecked(e);
    } finally {
        // ?Stream
        IOUtils.closeQuietly(in);
    }
}

From source file:com.ibm.jaggr.core.resource.AggregationResource.java

@Override
public InputStream getInputStream() throws IOException {
    return new ReaderInputStream(getReader(), "UTF-8"); //$NON-NLS-1$
}