Search in sources :

Example 41 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project linuxtools by eclipse.

the class AbstractDockerBotTest method getResourceAsString.

protected String getResourceAsString(String path) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copy(VolumeMountTest.class.getResourceAsStream("/" + path), out);
    return new String(out.toByteArray());
}
Also used : VolumeMountTest(org.eclipse.linuxtools.docker.integration.tests.container.VolumeMountTest) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream)

Example 42 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project vboard by voyages-sncf-technologies.

the class UploadsManager method getAvatar.

/**
 * Get the base64 encoded avatar of a profil (user or team)
 *
 * @return String base64 encoded image
 */
public String getAvatar(String name) {
    try {
        BufferedImage img = ImageIO.read(getAvatarImagesDirectory().resolve(name + ".png").toFile());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ImageIO.write(img, "png", bos);
        byte[] imageBytes = bos.toByteArray();
        bos.close();
        return Base64.getEncoder().encodeToString(imageBytes);
    } catch (IOException e) {
        throw new VBoardException("Avatar encoding error", e);
    }
}
Also used : VBoardException(com.vsct.vboard.models.VBoardException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage)

Example 43 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project hive by apache.

the class QTestUtil method executeCmd.

private static QTestProcessExecResult executeCmd(String[] args, String outFile, String errFile) throws Exception {
    System.out.println("Running: " + org.apache.commons.lang.StringUtils.join(args, ' '));
    PrintStream out = outFile == null ? SessionState.getConsole().getChildOutStream() : new PrintStream(new FileOutputStream(outFile), true, "UTF-8");
    PrintStream err = errFile == null ? SessionState.getConsole().getChildErrStream() : new PrintStream(new FileOutputStream(errFile), true, "UTF-8");
    Process executor = Runtime.getRuntime().exec(args);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PrintStream str = new PrintStream(bos, true, "UTF-8");
    StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, err);
    StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, out, str);
    outPrinter.start();
    errPrinter.start();
    int result = executor.waitFor();
    outPrinter.join();
    errPrinter.join();
    if (outFile != null) {
        out.close();
    }
    if (errFile != null) {
        err.close();
    }
    return QTestProcessExecResult.create(result, new String(bos.toByteArray(), StandardCharsets.UTF_8));
}
Also used : SortAndDigestPrintStream(org.apache.hadoop.hive.common.io.SortAndDigestPrintStream) CachingPrintStream(org.apache.hadoop.hive.common.io.CachingPrintStream) DigestPrintStream(org.apache.hadoop.hive.common.io.DigestPrintStream) SortPrintStream(org.apache.hadoop.hive.common.io.SortPrintStream) PrintStream(java.io.PrintStream) StreamPrinter(org.apache.hive.common.util.StreamPrinter) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream)

Example 44 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project hive by apache.

the class TestExplainTask method explainToString.

private <K, V> String explainToString(Map<K, V> explainMap) throws Exception {
    ExplainWork work = new ExplainWork();
    ParseContext pCtx = new ParseContext();
    HashMap<String, TableScanOperator> topOps = new HashMap<>();
    TableScanOperator scanOp = new DummyOperator(new DummyExplainDesc<K, V>(explainMap));
    topOps.put("sample", scanOp);
    pCtx.setTopOps(topOps);
    work.setParseContext(pCtx);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    work.setConfig(new ExplainConfiguration());
    ExplainTask newExplainTask = new ExplainTask();
    newExplainTask.queryState = uut.queryState;
    newExplainTask.getJSONLogicalPlan(new PrintStream(baos), work);
    baos.close();
    return baos.toString();
}
Also used : PrintStream(java.io.PrintStream) ExplainConfiguration(org.apache.hadoop.hive.ql.parse.ExplainConfiguration) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ParseContext(org.apache.hadoop.hive.ql.parse.ParseContext)

Example 45 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project knime-core by knime.

the class BinaryObjectCellFactory method getHexDump.

/**
 * Utility method to get a hex dump of a binary input stream. Used in the value renderer.
 * @param in The input stream to read from (close will be called!)
 * @param length The maximum length to read (e.g. 1024 * 1024 * 1024 for a MB)
 * @return The hex dump, possible with a new line that the dump is truncated
 * @throws IOException If reading the stream fails.
 */
public static String getHexDump(final InputStream in, final int length) throws IOException {
    byte[] bs = new byte[length];
    int i = 0;
    while (i < length) {
        int read = in.read(bs, i, length - i);
        if (read < 0) {
            break;
        }
        i += read;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    HexDump.dump(bs, 0, out, 0);
    String s = new String(out.toByteArray());
    if (in.read() >= 0) {
        s = s.concat("...");
    }
    in.close();
    return s;
}
Also used : ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)92 Test (org.junit.Test)36 DataOutputStream (java.io.DataOutputStream)15 IOException (java.io.IOException)14 HashSet (java.util.HashSet)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)12 Configuration (org.apache.hadoop.conf.Configuration)12 PrintStream (java.io.PrintStream)10 SparkConf (org.apache.spark.SparkConf)10 Edge (uk.gov.gchq.gaffer.data.element.Edge)10 Element (uk.gov.gchq.gaffer.data.element.Element)10 Entity (uk.gov.gchq.gaffer.data.element.Entity)10 Graph (uk.gov.gchq.gaffer.graph.Graph)10 User (uk.gov.gchq.gaffer.user.User)10 File (java.io.File)9 HashMap (java.util.HashMap)8 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)6 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)6