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


Java PipedInputStream.close方法代码示例

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


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

示例1: testTestCommand

import java.io.PipedInputStream; //导入方法依赖的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: verifyJobPriority

import java.io.PipedInputStream; //导入方法依赖的package包/类
protected void verifyJobPriority(String jobId, String priority,
    Configuration conf, CLI jc) throws Exception {
  PipedInputStream pis = new PipedInputStream();
  PipedOutputStream pos = new PipedOutputStream(pis);
  int exitCode = runTool(conf, jc, new String[] { "-list", "all" }, pos);
  assertEquals("Exit code", 0, exitCode);
  BufferedReader br = new BufferedReader(new InputStreamReader(pis));
  String line;
  while ((line = br.readLine()) != null) {
    LOG.info("line = " + line);
    if (!line.contains(jobId)) {
      continue;
    }
    assertTrue(line.contains(priority));
    break;
  }
  pis.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestMRJobClient.java

示例3: checkPrintAllValues

import java.io.PipedInputStream; //导入方法依赖的package包/类
private static boolean checkPrintAllValues(JMXGet jmx) throws Exception {
  int size = 0; 
  byte[] bytes = null;
  String pattern = "List of all the available keys:";
  PipedOutputStream pipeOut = new PipedOutputStream();
  PipedInputStream pipeIn = new PipedInputStream(pipeOut);
  System.setErr(new PrintStream(pipeOut));
  jmx.printAllValues();
  if ((size = pipeIn.available()) != 0) {
    bytes = new byte[size];
    pipeIn.read(bytes, 0, bytes.length);            
  }
  pipeOut.close();
  pipeIn.close();
  return bytes != null ? new String(bytes).contains(pattern) : false;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestJMXGet.java

示例4: sshCall

import java.io.PipedInputStream; //导入方法依赖的package包/类
protected void sshCall(String username, String password, SshExecutor executor, String channelType) {
    try {
        JSch jsch = new JSch();
        Session session = jsch.getSession(username, props.getShell().getHost(), props.getShell().getPort());
        session.setPassword(password);
        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.connect();
        Channel channel = session.openChannel(channelType);
        PipedInputStream pis = new PipedInputStream();
        PipedOutputStream pos = new PipedOutputStream();
        channel.setInputStream(new PipedInputStream(pos));
        channel.setOutputStream(new PipedOutputStream(pis));
        channel.connect();
        try {
            executor.execute(pis, pos);
        } finally {
            pis.close();
            pos.close();
            channel.disconnect();
            session.disconnect();
        }
    } catch(JSchException | IOException ex) {
        fail(ex.toString());
    }
}
 
开发者ID:anand1st,项目名称:sshd-shell-spring-boot,代码行数:28,代码来源:AbstractSshSupport.java

示例5: verifyJobName

import java.io.PipedInputStream; //导入方法依赖的package包/类
protected void verifyJobName(String jobId, String name,
    Configuration conf, CLI jc) throws Exception {
  PipedInputStream pis = new PipedInputStream();
  PipedOutputStream pos = new PipedOutputStream(pis);
  int exitCode = runTool(conf, jc,
      new String[] { "-list", "all" }, pos);
  assertEquals("Exit code", 0, exitCode);
  BufferedReader br = new BufferedReader(new InputStreamReader(pis));
  String line = null;
  while ((line = br.readLine()) != null) {
    LOG.info("line = " + line);
    if (!line.contains(jobId)) {
      continue;
    }
    assertTrue(line.contains(name));
    break;
  }
  pis.close();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:20,代码来源:TestMRJobClient.java

示例6: checkPrintAllValues

import java.io.PipedInputStream; //导入方法依赖的package包/类
private static boolean checkPrintAllValues(JMXGet jmx) throws Exception {
  int size = 0; 
  byte[] bytes = null;
  String pattern = "List of all the available keys:";
  PipedOutputStream pipeOut = new PipedOutputStream();
  PipedInputStream pipeIn = new PipedInputStream(pipeOut);
  PrintStream oldErr = System.err;
  System.setErr(new PrintStream(pipeOut));
  try {
    jmx.printAllValues();
    if ((size = pipeIn.available()) != 0) {
      bytes = new byte[size];
      pipeIn.read(bytes, 0, bytes.length);
    }
    pipeOut.close();
    pipeIn.close();
  } finally {
    System.setErr(oldErr);
  }
  return bytes != null ? new String(bytes).contains(pattern) : false;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:22,代码来源:TestJMXGet.java

示例7: checkOutput

import java.io.PipedInputStream; //导入方法依赖的package包/类
private void checkOutput(String[] args, String pattern, PrintStream out,
    Class<?> clazz) {       
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  try {
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut, PIPE_BUFFER_SIZE);
    if (out == System.out) {
      System.setOut(new PrintStream(pipeOut));
    } else if (out == System.err) {
      System.setErr(new PrintStream(pipeOut));
    }

    if (clazz == DelegationTokenFetcher.class) {
      expectDelegationTokenFetcherExit(args);
    } else if (clazz == JMXGet.class) {
      expectJMXGetExit(args);
    } else if (clazz == DFSAdmin.class) {
      expectDfsAdminPrint(args);
    }
    pipeOut.close();
    ByteStreams.copy(pipeIn, outBytes);      
    pipeIn.close();
    assertTrue(new String(outBytes.toByteArray()).contains(pattern));            
  } catch (Exception ex) {
    fail("checkOutput error " + ex);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestTools.java

示例8: integrateLocalisedMessageBundle

import java.io.PipedInputStream; //导入方法依赖的package包/类
@Override
public void integrateLocalisedMessageBundle(Properties p) {
	// Surely there's a more convenient way of doing this?
	ResourceBundle rb = null;
	try {
		PipedInputStream in_stream = new PipedInputStream();
		PipedOutputStream out_stream = new PipedOutputStream(in_stream);
		p.store(out_stream, "");
		out_stream.close();
		rb = new PropertyResourceBundle(in_stream);
		in_stream.close();
	}
	catch (IOException ioe) {return;}
	integrateLocalisedMessageBundle(rb);
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:16,代码来源:LocaleUtilitiesImpl.java

示例9: checkOutput

import java.io.PipedInputStream; //导入方法依赖的package包/类
private void checkOutput(String[] args, String pattern, PrintStream out,
    Class<?> clazz) {       
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  PrintStream oldOut = System.out;
  PrintStream oldErr = System.err;
  try {
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut, PIPE_BUFFER_SIZE);
    if (out == System.out) {
      System.setOut(new PrintStream(pipeOut));
    } else if (out == System.err) {
      System.setErr(new PrintStream(pipeOut));
    }

    if (clazz == DelegationTokenFetcher.class) {
      expectDelegationTokenFetcherExit(args);
    } else if (clazz == JMXGet.class) {
      expectJMXGetExit(args);
    } else if (clazz == DFSAdmin.class) {
      expectDfsAdminPrint(args);
    }
    pipeOut.close();
    ByteStreams.copy(pipeIn, outBytes);      
    pipeIn.close();
    assertTrue(new String(outBytes.toByteArray()).contains(pattern));            
  } catch (Exception ex) {
    fail("checkOutput error " + ex);
  } finally {
    System.setOut(oldOut);
    System.setErr(oldErr);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:33,代码来源:TestTools.java

示例10: integrateLocalisedMessageBundle

import java.io.PipedInputStream; //导入方法依赖的package包/类
public void integrateLocalisedMessageBundle(Properties p) {
	// Surely there's a more convenient way of doing this?
	ResourceBundle rb = null;
	try {
		PipedInputStream in_stream = new PipedInputStream();
		PipedOutputStream out_stream = new PipedOutputStream(in_stream);
		p.store(out_stream, "");
		out_stream.close();
		rb = new PropertyResourceBundle(in_stream);
		in_stream.close();
	}
	catch (IOException ioe) {return;}
	integrateLocalisedMessageBundle(rb);
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:15,代码来源:LocaleUtilitiesImpl.java

示例11: getPifData

import java.io.PipedInputStream; //导入方法依赖的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

示例12: TarEntrySupplicant

import java.io.PipedInputStream; //导入方法依赖的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


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