Search in sources :

Example 26 with PipedOutputStream

use of java.io.PipedOutputStream in project pentaho-kettle by pentaho.

the class Log4jPipedAppenderTest method doAppend.

@Test
public void doAppend() throws IOException {
    PipedOutputStream pipedOutputStream = mock(PipedOutputStream.class);
    LoggingEvent loggingEvent = mock(LoggingEvent.class);
    Layout testLayout = mock(Layout.class);
    when(testLayout.format(loggingEvent)).thenReturn("LOG_TEST_LINE");
    log4jPipedAppender.setLayout(testLayout);
    log4jPipedAppender.setPipedOutputStream(pipedOutputStream);
    log4jPipedAppender.doAppend(loggingEvent);
    verify(pipedOutputStream).write(("LOG_TEST_LINE" + Const.CR).getBytes());
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Layout(org.apache.log4j.Layout) PipedOutputStream(java.io.PipedOutputStream) Test(org.junit.Test)

Example 27 with PipedOutputStream

use of java.io.PipedOutputStream in project jdk8u_jdk by JetBrains.

the class StandardMidiFileWriter method getFileStream.

//=================================================================================
private InputStream getFileStream(int type, Sequence sequence) throws IOException {
    Track[] tracks = sequence.getTracks();
    int bytesBuilt = 0;
    int headerLength = 14;
    int length = 0;
    int timeFormat;
    float divtype;
    PipedOutputStream hpos = null;
    DataOutputStream hdos = null;
    PipedInputStream headerStream = null;
    InputStream[] trackStreams = null;
    InputStream trackStream = null;
    InputStream fStream = null;
    // Determine the filetype to write
    if (type == MIDI_TYPE_0) {
        if (tracks.length != 1) {
            return null;
        }
    } else if (type == MIDI_TYPE_1) {
        if (tracks.length < 1) {
            // $$jb: 05.31.99: we _can_ write TYPE_1 if tracks.length==1
            return null;
        }
    } else {
        if (tracks.length == 1) {
            type = MIDI_TYPE_0;
        } else if (tracks.length > 1) {
            type = MIDI_TYPE_1;
        } else {
            return null;
        }
    }
    // Now build the file one track at a time
    // Note that above we made sure that MIDI_TYPE_0 only happens
    // if tracks.length==1
    trackStreams = new InputStream[tracks.length];
    int trackCount = 0;
    for (int i = 0; i < tracks.length; i++) {
        try {
            trackStreams[trackCount] = writeTrack(tracks[i], type);
            trackCount++;
        } catch (InvalidMidiDataException e) {
            if (Printer.err)
                Printer.err("Exception in write: " + e.getMessage());
        }
    //bytesBuilt += trackStreams[i].getLength();
    }
    // Now seqence the track streams
    if (trackCount == 1) {
        trackStream = trackStreams[0];
    } else if (trackCount > 1) {
        trackStream = trackStreams[0];
        for (int i = 1; i < tracks.length; i++) {
            // don't include failed track streams
            if (trackStreams[i] != null) {
                trackStream = new SequenceInputStream(trackStream, trackStreams[i]);
            }
        }
    } else {
        throw new IllegalArgumentException("invalid MIDI data in sequence");
    }
    // Now build the header...
    hpos = new PipedOutputStream();
    hdos = new DataOutputStream(hpos);
    headerStream = new PipedInputStream(hpos);
    // Write the magic number
    hdos.writeInt(MThd_MAGIC);
    // Write the header length
    hdos.writeInt(headerLength - 8);
    // Write the filetype
    if (type == MIDI_TYPE_0) {
        hdos.writeShort(0);
    } else {
        // MIDI_TYPE_1
        hdos.writeShort(1);
    }
    // Write the number of tracks
    hdos.writeShort((short) trackCount);
    // Determine and write the timing format
    divtype = sequence.getDivisionType();
    if (divtype == Sequence.PPQ) {
        timeFormat = sequence.getResolution();
    } else if (divtype == Sequence.SMPTE_24) {
        timeFormat = (24 << 8) * -1;
        timeFormat += (sequence.getResolution() & 0xFF);
    } else if (divtype == Sequence.SMPTE_25) {
        timeFormat = (25 << 8) * -1;
        timeFormat += (sequence.getResolution() & 0xFF);
    } else if (divtype == Sequence.SMPTE_30DROP) {
        timeFormat = (29 << 8) * -1;
        timeFormat += (sequence.getResolution() & 0xFF);
    } else if (divtype == Sequence.SMPTE_30) {
        timeFormat = (30 << 8) * -1;
        timeFormat += (sequence.getResolution() & 0xFF);
    } else {
        // $$jb: 04.08.99: What to really do here?
        return null;
    }
    hdos.writeShort(timeFormat);
    // now construct an InputStream to become the FileStream
    fStream = new SequenceInputStream(headerStream, trackStream);
    hdos.close();
    length = bytesBuilt + headerLength;
    return fStream;
}
Also used : InvalidMidiDataException(javax.sound.midi.InvalidMidiDataException) SequenceInputStream(java.io.SequenceInputStream) DataOutputStream(java.io.DataOutputStream) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Track(javax.sound.midi.Track)

Example 28 with PipedOutputStream

use of java.io.PipedOutputStream in project JMRI by JMRI.

the class DCCppStreamPortControllerTest method setUp.

// The minimal setup for log4J
@Override
@Before
public void setUp() {
    apps.tests.Log4JFixture.setUp();
    JUnitUtil.resetInstanceManager();
    try {
        PipedInputStream tempPipe;
        tempPipe = new PipedInputStream();
        DataOutputStream ostream = new DataOutputStream(new PipedOutputStream(tempPipe));
        tempPipe = new PipedInputStream();
        DataInputStream istream = new DataInputStream(tempPipe);
        apc = new DCCppStreamPortController(istream, ostream, "Test");
    } catch (java.io.IOException ioe) {
        Assert.fail("IOException creating stream");
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) DataInputStream(java.io.DataInputStream) Before(org.junit.Before)

Example 29 with PipedOutputStream

use of java.io.PipedOutputStream in project JMRI by JMRI.

the class XNetStreamPortControllerTest method setUp.

// The minimal setup for log4J
@Override
@Before
public void setUp() {
    apps.tests.Log4JFixture.setUp();
    JUnitUtil.resetInstanceManager();
    try {
        PipedInputStream tempPipe;
        tempPipe = new PipedInputStream();
        DataOutputStream ostream = new DataOutputStream(new PipedOutputStream(tempPipe));
        tempPipe = new PipedInputStream();
        DataInputStream istream = new DataInputStream(tempPipe);
        apc = new XNetStreamPortController(istream, ostream, "Test");
    } catch (java.io.IOException ioe) {
        Assert.fail("IOException creating stream");
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) DataInputStream(java.io.DataInputStream) Before(org.junit.Before)

Example 30 with PipedOutputStream

use of java.io.PipedOutputStream in project JMRI by JMRI.

the class Z21XNetStreamPortControllerTest method setUp.

// The minimal setup for log4J
@Override
@Before
public void setUp() {
    apps.tests.Log4JFixture.setUp();
    JUnitUtil.resetInstanceManager();
    try {
        PipedInputStream tempPipe;
        tempPipe = new PipedInputStream();
        DataOutputStream ostream = new DataOutputStream(new PipedOutputStream(tempPipe));
        tempPipe = new PipedInputStream();
        DataInputStream istream = new DataInputStream(tempPipe);
        apc = new Z21XNetStreamPortController(istream, ostream, "Test");
    } catch (java.io.IOException ioe) {
        Assert.fail("IOException creating stream");
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) DataInputStream(java.io.DataInputStream) Before(org.junit.Before)

Aggregations

PipedOutputStream (java.io.PipedOutputStream)227 PipedInputStream (java.io.PipedInputStream)204 IOException (java.io.IOException)91 Test (org.junit.Test)55 InputStream (java.io.InputStream)28 OutputStream (java.io.OutputStream)24 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)21 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)21 PrintStream (java.io.PrintStream)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)19 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)17 TypeToken (com.google.common.reflect.TypeToken)17 InputStreamReader (java.io.InputStreamReader)16 DataInputStream (java.io.DataInputStream)14 DataOutputStream (java.io.DataOutputStream)14 BufferedReader (java.io.BufferedReader)13 Before (org.junit.Before)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ExecutorService (java.util.concurrent.ExecutorService)8 ArrayList (java.util.ArrayList)7