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