当前位置: 首页>>代码示例>>Java>>正文


Java PipedOutputStream.write方法代码示例

本文整理汇总了Java中java.io.PipedOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java PipedOutputStream.write方法的具体用法?Java PipedOutputStream.write怎么用?Java PipedOutputStream.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.PipedOutputStream的用法示例。


在下文中一共展示了PipedOutputStream.write方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTestCommand

import java.io.PipedOutputStream; //导入方法依赖的package包/类
@Test
public void testTestCommand() throws JSchException, IOException {
    JSch jsch = new JSch();
    Session session = jsch.getSession("admin", "localhost", properties.getShell().getPort());
    jsch.addIdentity("src/test/resources/id_rsa");
    Properties config = new Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect();
    ChannelShell channel = (ChannelShell) session.openChannel("shell");
    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    channel.setInputStream(new PipedInputStream(pos));
    channel.setOutputStream(new PipedOutputStream(pis));
    channel.connect();
    pos.write("test run bob\r".getBytes(StandardCharsets.UTF_8));
    pos.flush();
    verifyResponse(pis, "test run bob");
    pis.close();
    pos.close();
    channel.disconnect();
    session.disconnect();
}
 
开发者ID:anand1st,项目名称:sshd-shell-spring-boot,代码行数:24,代码来源:SshdShellAutoConfigurationWithPublicKeyAndBannerImageTest.java

示例2: tupleWriter

import java.io.PipedOutputStream; //导入方法依赖的package包/类
private void tupleWriter(PipedOutputStream pipeOut, Set<String> tuples) throws BiremeException {
  byte[] data = null;

  try {
    Iterator<String> iterator = tuples.iterator();

    while (iterator.hasNext() && !cxt.stop) {
      data = iterator.next().getBytes("UTF-8");
      pipeOut.write(data);
    }

    pipeOut.flush();
  } catch (IOException e) {
    throw new BiremeException("I/O error occurs while write to pipe.", e);
  } finally {
    try {
      pipeOut.close();
    } catch (IOException ignore) {
    }
  }
}
 
开发者ID:HashDataInc,项目名称:bireme,代码行数:22,代码来源:ChangeLoader.java

示例3: canHandleDataNotAlreadyPresentSeparatedByNewline

import java.io.PipedOutputStream; //导入方法依赖的package包/类
@Test
public void canHandleDataNotAlreadyPresentSeparatedByNewline()
		throws Exception {
	List<String> expected = Arrays.asList("a", "b", "c");

	PipedOutputStream os = new PipedOutputStream();
	PipedInputStream is = new PipedInputStream(os);

	StreamReader reader = process(is, "\n", expected);

	TimeUnit.SECONDS.sleep(2);
	os.write("a\nb\nc\n".getBytes());

	waitUntil(expected.size());
	assertThat(received, is(expected));
	reader.close();
}
 
开发者ID:Ardulink,项目名称:Ardulink-2,代码行数:18,代码来源:StreamReaderTest.java

示例4: canHandleDataNotAlreadyPresentSeparatedByComma

import java.io.PipedOutputStream; //导入方法依赖的package包/类
@Test
public void canHandleDataNotAlreadyPresentSeparatedByComma()
		throws Exception {
	List<String> expected = Arrays.asList("a", "b", "c");

	PipedOutputStream os = new PipedOutputStream();
	PipedInputStream is = new PipedInputStream(os);

	StreamReader reader = process(is, ",", expected);

	TimeUnit.SECONDS.sleep(2);
	os.write("a,b,c,".getBytes());

	waitUntil(expected.size());
	assertThat(received, is(expected));
	reader.close();
}
 
开发者ID:Ardulink,项目名称:Ardulink-2,代码行数:18,代码来源:StreamReaderTest.java

示例5: testStopDetectingInputBufferWaitStop

import java.io.PipedOutputStream; //导入方法依赖的package包/类
public void testStopDetectingInputBufferWaitStop() throws Exception {
    Runnable shouldNotHappenRun =
            () -> { throw new AssertionError("Should not happen."); };
    Consumer<Exception> shouldNotHappenExc =
            exc -> { throw new AssertionError("Should not happen.", exc); };
    StopDetectingInputStream sd = new StopDetectingInputStream(shouldNotHappenRun, shouldNotHappenExc);
    CountDownLatch reading = new CountDownLatch(1);
    PipedInputStream is = new PipedInputStream() {
        @Override
        public int read() throws IOException {
            reading.countDown();
            return super.read();
        }
    };
    PipedOutputStream os = new PipedOutputStream(is);

    sd.setInputStream(is);
    sd.setState(State.BUFFER);
    reading.await();
    sd.setState(State.WAIT);
    os.write(3);
    int value = sd.read();

    if (value != 3) {
        throw new AssertionError();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:StopExecutionTest.java

示例6: setUp

import java.io.PipedOutputStream; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {

  outputStream = new ByteArrayOutputStream();
  pipe = new PipedOutputStream();

  connection = new BluetoothConnectionBase(outputStream, new PipedInputStream(pipe)) {
    @Override
    protected void bluetoothError(String functionName, int errorNumber, Object... messageArgs) {
      recordedErrorNumber = errorNumber;
    }
    @Override
    protected void write(String functionName, byte b) {
      super.write(functionName, b);
      try {
        pipe.write(b);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    @Override
    protected void write(String functionName, byte[] bytes) {
      super.write(functionName, bytes);
      try {
        pipe.write(bytes);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  };
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:32,代码来源:BluetoothConnectionBaseTest.java

示例7: testPopLength

import java.io.PipedOutputStream; //导入方法依赖的package包/类
/**
 * Test the static utility method that grabs the first four bytes from an
 * input stream and returns their value as an int.
 */
@Test
public void testPopLength() throws IOException {
  int testValue = 42;
  PipedInputStream inputStream = new PipedInputStream();
  PipedOutputStream outputStream = new PipedOutputStream();
  outputStream.connect(inputStream);
  
  ByteBuffer b = ByteBuffer.allocate(4);
  b.order(ByteOrder.BIG_ENDIAN);   // Network byte order.
  b.putInt(testValue);
  outputStream.write(b.array());
  assertEquals(testValue, Exchange.popLength(inputStream));
}
 
开发者ID:casific,项目名称:murmur,代码行数:18,代码来源:ExchangeTest.java

示例8: getInputStream

import java.io.PipedOutputStream; //导入方法依赖的package包/类
/**
 * @param length
 *            The length of the stream content.
 * @return An InputStream.
 * @throws IOException
 *             Exception.
 */
private PipedInputStream getInputStream(long length) throws IOException {
    PipedOutputStream outputStream = new PipedOutputStream();
    PipedInputStream inputStream = new PipedInputStream(outputStream);
    for (int i = 0; i < length; i++) {
        outputStream.write(Byte.MIN_VALUE);
    }
    outputStream.flush();
    outputStream.close();
    return inputStream;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:18,代码来源:IOHelperTest.java

示例9: TarEntrySupplicant

import java.io.PipedOutputStream; //导入方法依赖的package包/类
/**
 * After instantiating a TarEntrySupplicant, the user must either invoke
 * write() or close(), to release system resources on the input
 * File/Stream.
 * <P>
 * <B>WARNING:</B>
 * Do not use this method unless the quantity of available RAM is
 * sufficient to accommodate the specified maxBytes all at one time.
 * This constructor loads all input from the specified InputStream into
 * RAM before anything is written to disk.
 * </P>
 *
 * @param maxBytes This method will fail if more than maxBytes bytes
 *                 are supplied on the specified InputStream.
 *                 As the type of this parameter enforces, the max
 *                 size you can request is 2GB.
 */
public TarEntrySupplicant(String path, InputStream origStream,
                          int maxBytes, char typeFlag,
                          TarFileOutputStream tarStream)
        throws IOException, TarMalformatException {

    /*
     * If you modify this, make sure to not intermix reading/writing of
     * the PipedInputStream and the PipedOutputStream, or you could
     * cause dead-lock.  Everything is safe if you close the
     * PipedOutputStream before reading the PipedInputStream.
     */
    this(path, typeFlag, tarStream, 0100000000000L);

    if (maxBytes < 1) {
        throw new IllegalArgumentException(RB.read_lt_1.getString());
    }

    int               i;
    PipedOutputStream outPipe = new PipedOutputStream();

    /*
     *  This constructor not available until Java 1.6:
     * inputStream = new PipedInputStream(outPipe, maxBytes);
     */
    try {
        inputStream =
            new InputStreamWrapper(new PipedInputStream(outPipe));

        while ((i =
                origStream.read(tarStream.writeBuffer, 0,
                                tarStream.writeBuffer.length)) > 0) {
            outPipe.write(tarStream.writeBuffer, 0, i);
        }

        outPipe.flush();    // Do any good on a pipe?
        dataSize = inputStream.available();

        if (TarFileOutputStream.debug) {
            System.out.println(
                RB.stream_buffer_report.getString(
                    Long.toString(dataSize)));
        }
    } catch (IOException ioe) {
        close();

        throw ioe;
    } finally {
        try {
            outPipe.close();
        } finally {
            outPipe = null;    // Encourage buffer GC
        }
    }

    modTime = new java.util.Date().getTime() / 1000L;
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:74,代码来源:TarGenerator.java

示例10: getPifData

import java.io.PipedOutputStream; //导入方法依赖的package包/类
protected PIFData getPifData(TarEntryHeader header)
throws IOException, TarMalformatException {

    /*
     * If you modify this, make sure to not intermix reading/writing of
     * the PipedInputStream and the PipedOutputStream, or you could
     * cause dead-lock.  Everything is safe if you close the
     * PipedOutputStream before reading the PipedInputStream.
     */
    long dataSize = header.getDataSize();

    if (dataSize < 1) {
        throw new TarMalformatException(
            RB.singleton.getString(RB.PIF_UNKNOWN_DATASIZE));
    }

    if (dataSize > Integer.MAX_VALUE) {
        throw new TarMalformatException(
            RB.singleton.getString(
                RB.PIF_DATA_TOOBIG, Long.toString(dataSize),
                Integer.MAX_VALUE));
    }

    int readNow;
    int readBlocks = (int) (dataSize / 512L);
    int modulus    = (int) (dataSize % 512L);

    // Couldn't care less about the entry "name" field.
    PipedOutputStream outPipe = new PipedOutputStream();
    PipedInputStream  inPipe  = new PipedInputStream(outPipe);

    /* This constructor not available until Java 1.6:
            new PipedInputStream(outPipe, (int) dataSize);
    */
    try {
        while (readBlocks > 0) {
            readNow = (readBlocks > archive.getReadBufferBlocks())
                      ? archive.getReadBufferBlocks()
                      : readBlocks;

            archive.readBlocks(readNow);

            readBlocks -= readNow;

            outPipe.write(archive.readBuffer, 0, readNow * 512);
        }

        if (modulus != 0) {
            archive.readBlock();
            outPipe.write(archive.readBuffer, 0, modulus);
        }

        outPipe.flush();    // Do any good on a pipe?
    } catch (IOException ioe) {
        inPipe.close();

        throw ioe;
    } finally {
        outPipe.close();
    }

    return new PIFData(inPipe);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:64,代码来源:TarReader.java

示例11: TarEntrySupplicant

import java.io.PipedOutputStream; //导入方法依赖的package包/类
/**
 * After instantiating a TarEntrySupplicant, the user must either invoke
 * write() or close(), to release system resources on the input
 * File/Stream.
 * <P/>
 * <B>WARNING:</B>
 * Do not use this method unless the quantity of available RAM is
 * sufficient to accommodate the specified maxBytes all at one time.
 * This constructor loads all input from the specified InputStream into
 * RAM before anything is written to disk.
 *
 * @param maxBytes This method will fail if more than maxBytes bytes
 *                 are supplied on the specified InputStream.
 *                 As the type of this parameter enforces, the max
 *                 size you can request is 2GB.
 */
public TarEntrySupplicant(String path, InputStream origStream,
                          int maxBytes, char typeFlag,
                          TarFileOutputStream tarStream)
                          throws IOException, TarMalformatException {

    /*
     * If you modify this, make sure to not intermix reading/writing of
     * the PipedInputStream and the PipedOutputStream, or you could
     * cause dead-lock.  Everything is safe if you close the
     * PipedOutputStream before reading the PipedInputStream.
     */
    this(path, typeFlag, tarStream);

    if (maxBytes < 1) {
        throw new IllegalArgumentException(
            RB.singleton.getString(RB.READ_LT_1));
    }

    int               i;
    PipedOutputStream outPipe = new PipedOutputStream();

    inputStream = new PipedInputStream(outPipe);

    /* This constructor not available until Java 1.6:
    inputStream = new PipedInputStream(outPipe, maxBytes);
    */
    try {
        while ((i =
                origStream
                    .read(tarStream.writeBuffer, 0, tarStream
                        .writeBuffer.length)) > 0) {
            outPipe.write(tarStream.writeBuffer, 0, i);
        }

        outPipe.flush();    // Do any good on a pipe?

        dataSize = inputStream.available();

        if (TarFileOutputStream.debug) {
            System.out.println(
                RB.singleton.getString(
                    RB.STREAM_BUFFER_REPORT, Long.toString(dataSize)));
        }
    } catch (IOException ioe) {
        inputStream.close();

        throw ioe;
    } finally {
        outPipe.close();
    }

    modTime = new java.util.Date().getTime() / 1000L;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:70,代码来源:TarGenerator.java

示例12: writeToPipedOutputStream

import java.io.PipedOutputStream; //导入方法依赖的package包/类
/**
 * Writes bytes to a PipedOutputStream and translates any IOException to an IllegalStateException.
 *
 * <p>PipedOutputStream throws IOException on write, not due to any environmental conditions, only
 * due to it being in an unwritable state. Some such states, such as not being connected to a
 * PipedInputStream, are impossible here. The rest, such as the fake process having terminated,
 * are rare and user-preventable, particuarly in the context of a test, which is expected to have
 * deterministic behavior. Moreover, if the write() methods did declare IOException, a test would
 * surely just rethrow it, so it's only impact would be added noise to the test code.
 */
private void writeToPipedOutputStream(PipedOutputStream pipedOutput, byte[] bytes) {
  try {
    pipedOutput.write(bytes);
  } catch (IOException e) {
    throw new IllegalStateException(e);
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:18,代码来源:FakeProcess.java


注:本文中的java.io.PipedOutputStream.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。