Search in sources :

Example 36 with ByteArrayOutputStream

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

the class JavaProcessMonitor method menuThreadDumpOnAction.

/**
	 * Thread Dump
	 * @작성자 : KYJ
	 * @작성일 : 2017. 1. 23.
	 * @param e
	 * @throws Exception
	 */
public void menuThreadDumpOnAction(ActionEvent e) {
    ApplicationModel selectedItem = getSelectedItem(item -> item);
    if (selectedItem == null) {
        Window window = FxUtil.getWindow(this.getParent(), () -> {
            return SharedMemory.getPrimaryStage();
        });
        DialogUtil.showMessageDialog(window, "덤프를 출력할 프로세스를 선택.");
        return;
    }
    Integer selectedProcessId = selectedItem.getProcessId();
    String applicationName = selectedItem.getApplicationName();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Monitors.runStackTool(selectedProcessId, out);
    ThreadDumpTextArea parent = new ThreadDumpTextArea();
    parent.setContent(out.toString());
    FxUtil.createStageAndShow(parent, stage -> {
        stage.initOwner(getParent().getScene().getWindow());
        stage.setWidth(1200d);
        stage.setHeight(800d);
        stage.setTitle("App - " + applicationName);
    });
//		FxUtil.createSimpleTextAreaAndShow(out.toString(), stage -> {
//
//
//		});
}
Also used : Window(javafx.stage.Window) ThreadDumpTextArea(com.kyj.fx.voeditor.visual.component.text.ThreadDumpTextArea) ApplicationModel(com.kyj.bci.monitor.ApplicationModel) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream)

Example 37 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project SSM by Intel-bigdata.

the class TestCheckStorageAction method testCheckStorageAction.

@Test
public void testCheckStorageAction() throws IOException {
    CheckStorageAction checkStorageAction = new CheckStorageAction();
    checkStorageAction.setDfsClient(dfsClient);
    checkStorageAction.setContext(smartContext);
    final String file = "/testParallelMovers/file1";
    dfsClient.mkdirs("/testParallelMovers");
    // write to HDFS
    final OutputStream out = dfsClient.create(file, true);
    byte[] content = ("This is a file containing two blocks" + "......................").getBytes();
    out.write(content);
    out.close();
    // do CheckStorageAction
    checkStorageAction.init(new String[] { file });
    checkStorageAction.run();
    ActionStatus actionStatus = checkStorageAction.getActionStatus();
    System.out.println(StringUtils.formatTime(actionStatus.getRunningTime()));
    Assert.assertTrue(actionStatus.isFinished());
    Assert.assertTrue(actionStatus.isSuccessful());
    Assert.assertEquals(1.0f, actionStatus.getPercentage(), 0.00001f);
    ByteArrayOutputStream resultStream = actionStatus.getResultStream();
    System.out.println(resultStream);
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ActionStatus(org.smartdata.actions.ActionStatus) Test(org.junit.Test)

Example 38 with ByteArrayOutputStream

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

the class DistributionPackageUtilsTest method testInfoFullStreams.

@Test
public void testInfoFullStreams() {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Map<String, Object> info = new HashMap<String, Object>();
    info.put("test1", "value1");
    info.put("test2", "value2");
    info.put("test3", new String[] { "value1", "value2" });
    DistributionPackageUtils.writeInfo(outputStream, info);
    InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    Map<String, Object> resultInfo = new HashMap<String, Object>();
    DistributionPackageUtils.readInfo(inputStream, resultInfo);
    assertEquals(info.size(), resultInfo.size());
    assertEquals("value1", resultInfo.get("test1"));
    assertEquals("value2", resultInfo.get("test2"));
    String[] array = (String[]) resultInfo.get("test3");
    assertEquals("value1", array[0]);
    assertEquals("value2", array[1]);
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 39 with ByteArrayOutputStream

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

the class SerDeUtils method toBytes.

/**
 * Serialize a profile measurement's value.
 *
 * The value produced by a Profile definition can be any numeric data type.  The data
 * type depends on how the profile is defined by the user.  The user should be able to
 * choose the data type that is most suitable for their use case.
 *
 * @param value The value to serialize.
 */
public static byte[] toBytes(Object value) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Output output = new Output(bos);
        kryo.get().writeClassAndObject(output, value);
        output.flush();
        bos.flush();
        return bos.toByteArray();
    } catch (Throwable t) {
        LOG.error("Unable to serialize: {} because {}", value, t.getMessage(), t);
        throw new IllegalStateException("Unable to serialize " + value + " because " + t.getMessage(), t);
    }
}
Also used : Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream)

Example 40 with ByteArrayOutputStream

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

the class ApplicationLink method getPlaintextStorageXml.

private byte[] getPlaintextStorageXml() throws Exception {
    ByteArrayOutputStream plaintextByteArrayOutputStream = new ByteArrayOutputStream();
    DataOutputStream plaintextOutputStream = new DataOutputStream(plaintextByteArrayOutputStream);
    plaintextOutputStream.writeInt(transferSettings.getType().getBytes().length);
    plaintextOutputStream.write(transferSettings.getType().getBytes());
    GZIPOutputStream plaintextGzipOutputStream = new GZIPOutputStream(plaintextOutputStream);
    new Persister(new Format(0)).write(transferSettings, plaintextGzipOutputStream);
    plaintextGzipOutputStream.close();
    return plaintextByteArrayOutputStream.toByteArray();
}
Also used : Format(org.simpleframework.xml.stream.Format) GZIPOutputStream(java.util.zip.GZIPOutputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Persister(org.simpleframework.xml.core.Persister)

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