java.security.spec.ECGenParameterSpec#com.google.common.io.ByteStreams源码实例Demo

下面列出了java.security.spec.ECGenParameterSpec#com.google.common.io.ByteStreams 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public InputStream doSeekLoad(long offset, int maxLength) throws IOException {
		
		if ((type == NIOType.MMAP) && (maxLength >= 0)) {
			ByteBuffer mapBuff = fc.map(MapMode.READ_ONLY, offset, maxLength);
			bbis = new ByteBufferBackedInputStream(mapBuff, offset);	
			return ByteStreams.limit(bbis, maxLength);
			
		} else {
			fcis = new FileChannelInputStream(fc, offset, maxLength);
			return fcis;
//			if (maxLength > 0) {
//				return new LimitInputStream(fcis, maxLength);
//			} else {
//				return fcis;
//			}
		}
    }
 
@Test
public void testCallRequest() throws Exception {
    final InputStream resource = getClass().getClassLoader().getResourceAsStream("callback-request.json");
    final byte[] requestBody = ByteStreams.toByteArray(resource);

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("X-Line-Signature", "SSSSIGNATURE");
    request.setContent(requestBody);

    doReturn(true).when(lineSignatureValidator).validateSignature(requestBody, "SSSSIGNATURE");

    final CallbackRequest callbackRequest = lineBotCallbackRequestParser.handle(request);

    assertThat(callbackRequest).isNotNull();

    final List<Event> result = callbackRequest.getEvents();

    final MessageEvent messageEvent = (MessageEvent) result.get(0);
    final TextMessageContent text = (TextMessageContent) messageEvent.getMessage();
    assertThat(text.getText()).isEqualTo("Hello, world");

    final String followedUserId = messageEvent.getSource().getUserId();
    assertThat(followedUserId).isEqualTo("u206d25c2ea6bd87c17655609a1c37cb8");
    assertThat(messageEvent.getTimestamp()).isEqualTo(Instant.parse("2016-05-07T13:57:59.859Z"));
}
 
源代码3 项目: BUbiNG   文件: GZIPArchiveWriterTest.java
public static void main(String[] args) throws IOException, JSAPException {

	SimpleJSAP jsap = new SimpleJSAP(GZIPArchiveReader.class.getName(), "Writes some random records on disk.",
		new Parameter[] {
			new Switch("fully", 'f', "fully",
				"Whether to read fully the record (and do a minimal cosnsistency check)."),
			new UnflaggedOption("path", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY,
				"The path to read from."), });

	JSAPResult jsapResult = jsap.parse(args);
	if (jsap.messagePrinted())
	    System.exit(1);

	final boolean fully = jsapResult.getBoolean("fully");
	GZIPArchiveReader gzar = new GZIPArchiveReader(new FileInputStream(jsapResult.getString("path")));
	for (;;) {
	    ReadEntry e = gzar.getEntry();
	    if (e == null)
		break;
	    InputStream inflater = e.lazyInflater.get();
	    if (fully)
		ByteStreams.toByteArray(inflater);
	    e.lazyInflater.consume();
	    System.out.println(e);
	}
    }
 
源代码4 项目: google-java-format   文件: MainTest.java
@Test
public void exitIfChangedStdin() throws Exception {
  Path path = testFolder.newFile("Test.java").toPath();
  Files.write(path, "class Test {\n}\n".getBytes(UTF_8));
  Process process =
      new ProcessBuilder(
              ImmutableList.of(
                  Paths.get(System.getProperty("java.home")).resolve("bin/java").toString(),
                  "-cp",
                  System.getProperty("java.class.path"),
                  Main.class.getName(),
                  "-n",
                  "--set-exit-if-changed",
                  "-"))
          .redirectInput(path.toFile())
          .redirectError(Redirect.PIPE)
          .redirectOutput(Redirect.PIPE)
          .start();
  process.waitFor();
  String err = new String(ByteStreams.toByteArray(process.getErrorStream()), UTF_8);
  String out = new String(ByteStreams.toByteArray(process.getInputStream()), UTF_8);
  assertThat(err).isEmpty();
  assertThat(out).isEqualTo("<stdin>" + System.lineSeparator());
  assertThat(process.exitValue()).isEqualTo(1);
}
 
源代码5 项目: HeyGirl   文件: DexBackedDexFile.java
public static DexBackedDexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is)
        throws IOException {
    if (!is.markSupported()) {
        throw new IllegalArgumentException("InputStream must support mark");
    }
    is.mark(44);
    byte[] partialHeader = new byte[44];
    try {
        ByteStreams.readFully(is, partialHeader);
    } catch (EOFException ex) {
        throw new NotADexFile("File is too short");
    } finally {
        is.reset();
    }

    verifyMagicAndByteOrder(partialHeader, 0);

    byte[] buf = ByteStreams.toByteArray(is);
    return new DexBackedDexFile(opcodes, buf, 0, false);
}
 
源代码6 项目: HubBasics   文件: LobbyCommand.java
@Override
public void execute(CommandSender commandSender, String[] strings) {
    ServerInfo serverInfo = this.getLobby();
    if (serverInfo != null && commandSender instanceof ProxiedPlayer) {
        ProxiedPlayer player = (ProxiedPlayer) commandSender;
        if (!player.getServer().getInfo().getName().equals(serverInfo.getName())) {
            player.connect(getLobby());
        } else {
            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF("HubBasics");
            out.writeUTF("Lobby");
            player.sendData("BungeeCord", out.toByteArray());
        }
    } else if (serverInfo == null) {
        commandSender.sendMessage(new TextComponent(Messages.get(commandSender, "LOBBY_NOT_DEFINED")));
    } else {
        commandSender.sendMessage(new TextComponent(Messages.get(commandSender, "COMMAND_PLAYER")));
    }
}
 
源代码7 项目: tlaplus   文件: CloudDistributedTLCJob.java
@Override
public void getJavaFlightRecording() throws IOException {
	// Get Java Flight Recording from remote machine and save if to a local file in
	// the current working directory. We call "cat" because sftclient#get fails with
	// the old net.schmizz.sshj and an update to the newer com.hierynomus seems 
	// awful lot of work.
	final ExecChannel channel = sshClient.execChannel("cat /mnt/tlc/tlc.jfr");
	final InputStream output = channel.getOutput();
	final String cwd = Paths.get(".").toAbsolutePath().normalize().toString() + File.separator;
	final File jfr = new File(cwd + "tlc-" + System.currentTimeMillis() + ".jfr");
	ByteStreams.copy(output, new FileOutputStream(jfr));
	if (jfr.length() == 0) {
		System.err.println("Received empty Java Flight recording. Not creating tlc.jfr file");
		jfr.delete();
	}
}
 
源代码8 项目: AppTroy   文件: DexBackedDexFile.java
public static DexBackedDexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is)
        throws IOException {
    if (!is.markSupported()) {
        throw new IllegalArgumentException("InputStream must support mark");
    }
    is.mark(44);
    byte[] partialHeader = new byte[44];
    try {
        ByteStreams.readFully(is, partialHeader);
    } catch (EOFException ex) {
        throw new NotADexFile("File is too short");
    } finally {
        is.reset();
    }

    verifyMagicAndByteOrder(partialHeader, 0);

    byte[] buf = ByteStreams.toByteArray(is);
    return new DexBackedDexFile(opcodes, buf, 0, false);
}
 
源代码9 项目: OpenYOLO-Android   文件: IoUtilTest.java
private byte[] writeAndRead(byte[] data, byte[] key) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CipherOutputStream outStream = IoUtil.encryptTo(baos, key);
    outStream.write(data);
    outStream.close();

    byte[] cipherText = baos.toByteArray();

    ByteArrayInputStream bais = new ByteArrayInputStream(cipherText);
    CipherInputStream inStream = IoUtil.decryptFrom(bais, key);

    byte[] result = ByteStreams.toByteArray(inStream);

    inStream.close();
    return result;
}
 
源代码10 项目: fenixedu-academic   文件: ThesisSubmissionDA.java
public ActionForward uploadAbstract(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ThesisFileBean bean = getRenderedObject();
    RenderUtils.invalidateViewState();

    if (bean != null && bean.getFile() != null) {
        byte[] bytes = ByteStreams.toByteArray(bean.getFile());
        try {
            CreateThesisAbstractFile.runCreateThesisAbstractFile(getThesis(request), bytes, bean.getSimpleFileName(), null,
                    null, null);
        } catch (DomainException e) {
            addActionMessage("error", request, e.getKey(), e.getArgs());
            return prepareUploadAbstract(mapping, actionForm, request, response);
        }
    }

    return prepareThesisSubmission(mapping, actionForm, request, response);
}
 
源代码11 项目: ChangeSkin   文件: PluginMessageListener.java
@EventHandler
public void onPluginMessage(PluginMessageEvent messageEvent) {
    String channel = messageEvent.getTag();
    if (messageEvent.isCancelled() || !channel.startsWith(plugin.getName().toLowerCase())) {
        return;
    }

    ByteArrayDataInput dataInput = ByteStreams.newDataInput(messageEvent.getData());

    ProxiedPlayer invoker = (ProxiedPlayer) messageEvent.getReceiver();
    if (channel.equals(permissionResultChannel)) {
        PermResultMessage message = new PermResultMessage();
        message.readFrom(dataInput);
        if (message.isAllowed()) {
            onPermissionSuccess(message, invoker);
        } else {
            plugin.sendMessage(invoker, "no-permission");
        }
    } else if (channel.equals(forwardCommandChannel)) {
        onCommandForward(invoker, dataInput);
    }
}
 
源代码12 项目: SkyWarsReloaded   文件: SkyWarsReloaded.java
public void sendSWRMessage(Player player, String server, ArrayList<String> messages) {
	ByteArrayDataOutput out = ByteStreams.newDataOutput();
	out.writeUTF("Forward"); 
	out.writeUTF(server);
	out.writeUTF("SWRMessaging");

	ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
	DataOutputStream msgout = new DataOutputStream(msgbytes);
	try {
		for (String msg: messages) {
			msgout.writeUTF(msg);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}

	out.writeShort(msgbytes.toByteArray().length);
	out.write(msgbytes.toByteArray());
	player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
 
源代码13 项目: bazel   文件: CompatDx.java
@SuppressWarnings("JdkObsolete") // Uses Enumeration by design.
private void writeInputClassesToArchive(DiagnosticsHandler handler) throws IOException {
  // For each input archive file, add all class files within.
  for (Path input : inputs) {
    if (FileUtils.isArchive(input)) {
      try (ZipFile zipFile = new ZipFile(input.toFile(), UTF_8)) {
        final Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
          ZipEntry entry = entries.nextElement();
          if (FileUtils.isClassFile(entry.getName())) {
            try (InputStream entryStream = zipFile.getInputStream(entry)) {
              byte[] bytes = ByteStreams.toByteArray(entryStream);
              writeClassFile(entry.getName(), ByteDataView.of(bytes), handler);
            }
          }
        }
      }
    }
  }
}
 
protected void write(int status, Map<String, String> headers, Object content) throws IOException {
  // write response status code
  servletResponse.setStatus(status);

  // write response headers
  if (headers != null) {
    for (Map.Entry<String, String> entry : headers.entrySet()) {
      servletResponse.addHeader(entry.getKey(), entry.getValue());
    }
  }

  // write response body
  if (content != null) {
    servletResponse.setContentType(SystemService.MIME_JSON);
    if (addContentLength) {
      CountingOutputStream counter = new CountingOutputStream(ByteStreams.nullOutputStream());
      objectWriter.writeValue(counter, content);
      servletResponse.setContentLength((int) counter.getCount());
    }
    objectWriter.writeValue(servletResponse.getOutputStream(), content);
  }
}
 
源代码15 项目: bazel   文件: DexFileAggregatorTest.java
@Test
public void testMultidex_underLimitWritesOneShard() throws Exception {
  DexFileAggregator dexer =
      new DexFileAggregator(
          new DxContext(),
          dest,
          newDirectExecutorService(),
          MultidexStrategy.BEST_EFFORT,
          /*forceJumbo=*/ false,
          DEX_LIMIT,
          WASTE,
          DexFileMergerTest.DEX_PREFIX);
  Dex dex2 = DexFiles.toDex(convertClass(ByteStreams.class));
  dexer.add(dex);
  dexer.add(dex2);
  verify(dest, times(0)).addFile(any(ZipEntry.class), any(Dex.class));
  dexer.close();
  verify(dest).addFile(any(ZipEntry.class), written.capture());
  assertThat(Iterables.size(written.getValue().classDefs())).isEqualTo(2);
}
 
源代码16 项目: bazel   文件: DarwinSandboxedSpawnRunner.java
private static boolean computeIsSupported() {
  List<String> args = new ArrayList<>();
  args.add(sandboxExecBinary);
  args.add("-p");
  args.add("(version 1) (allow default)");
  args.add("/usr/bin/true");

  ImmutableMap<String, String> env = ImmutableMap.of();
  File cwd = new File("/usr/bin");

  Command cmd = new Command(args.toArray(new String[0]), env, cwd);
  try {
    cmd.execute(ByteStreams.nullOutputStream(), ByteStreams.nullOutputStream());
  } catch (CommandException e) {
    return false;
  }

  return true;
}
 
源代码17 项目: s3proxy   文件: NullBlobStoreTest.java
@Test
public void testCreateBlobGetBlob() throws Exception {
    String blobName = createRandomBlobName();
    Blob blob = makeBlob(nullBlobStore, blobName);
    nullBlobStore.putBlob(containerName, blob);

    blob = nullBlobStore.getBlob(containerName, blobName);
    validateBlobMetadata(blob.getMetadata());

    // content differs, only compare length
    try (InputStream actual = blob.getPayload().openStream();
            InputStream expected = BYTE_SOURCE.openStream()) {
        long actualLength = ByteStreams.copy(actual,
                ByteStreams.nullOutputStream());
        long expectedLength = ByteStreams.copy(expected,
                ByteStreams.nullOutputStream());
        assertThat(actualLength).isEqualTo(expectedLength);
    }

    PageSet<? extends StorageMetadata> pageSet = nullBlobStore.list(
            containerName);
    assertThat(pageSet).hasSize(1);
    StorageMetadata sm = pageSet.iterator().next();
    assertThat(sm.getName()).isEqualTo(blobName);
    assertThat(sm.getSize()).isEqualTo(0);
}
 
源代码18 项目: android-chunk-utils   文件: ResourceString.java
/**
 * Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string.
 * Strings are prefixed by 2 values. The first is the number of characters in the string.
 * The second is the encoding length (number of bytes in the string).
 *
 * <p>Here's an example UTF-8-encoded string of ab©:
 * <pre>03 04 61 62 C2 A9 00</pre>
 *
 * @param str The string to be encoded.
 * @param type The encoding type that the {@link ResourceString} should be encoded in.
 * @return The encoded string.
 */
public static byte[] encodeString(String str, Type type) {
  byte[] bytes = str.getBytes(type.charset());
  // The extra 5 bytes is for metadata (character count + byte count) and the NULL terminator.
  ByteArrayDataOutput output = ByteStreams.newDataOutput(bytes.length + 5);
  encodeLength(output, str.length(), type);
  if (type == Type.UTF8) {  // Only UTF-8 strings have the encoding length.
    encodeLength(output, bytes.length, type);
  }
  output.write(bytes);
  // NULL-terminate the string
  if (type == Type.UTF8) {
    output.write(0);
  } else {
    output.writeShort(0);
  }
  return output.toByteArray();
}
 
源代码19 项目: che   文件: URLFetcher.java
/**
 * Fetch the urlConnection stream by using the urlconnection and return its content To prevent DOS
 * attack, limit the amount of the collected data
 *
 * @param urlConnection the URL connection to fetch
 * @return the content of the file
 * @throws IOException if fetch error occurs
 */
@VisibleForTesting
String fetch(@NotNull URLConnection urlConnection) throws IOException {
  requireNonNull(urlConnection, "urlConnection parameter can't be null");
  final String value;
  try (InputStream inputStream = urlConnection.getInputStream();
      BufferedReader reader =
          new BufferedReader(
              new InputStreamReader(ByteStreams.limit(inputStream, getLimit()), UTF_8))) {
    value = reader.lines().collect(Collectors.joining("\n"));
  } catch (IOException e) {
    // we shouldn't fetch if check is done before
    LOG.debug("Invalid URL", e);
    throw e;
  }
  return value;
}
 
源代码20 项目: SkyWarsReloaded   文件: SkyWarsReloaded.java
public void sendSWRMessage(Player player, String server, ArrayList<String> messages) {
	ByteArrayDataOutput out = ByteStreams.newDataOutput();
	out.writeUTF("Forward"); 
	out.writeUTF(server);
	out.writeUTF("SWRMessaging");

	ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
	DataOutputStream msgout = new DataOutputStream(msgbytes);
	try {
		for (String msg: messages) {
			msgout.writeUTF(msg);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}

	out.writeShort(msgbytes.toByteArray().length);
	out.write(msgbytes.toByteArray());
	player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
 
源代码21 项目: BUbiNG   文件: GZIPArchiveWriterTest.java
@Test
   public void readWrite() throws IOException {
List<byte[]> contents = writeArchive(ARCHIVE_PATH, ARCHIVE_SIZE, false);
FileInputStream fis = new FileInputStream(ARCHIVE_PATH);
GZIPArchiveReader gzar = new GZIPArchiveReader(fis);
GZIPArchive.ReadEntry re;
for (byte[] expected: contents) {
    re = gzar.getEntry();
    if (re == null) break;
    LazyInflater lin = re.lazyInflater;
    final byte[] actual = ByteStreams.toByteArray(lin.get());
    assertArrayEquals(expected, actual);
    lin.consume();
}
fis.close();
   }
 
源代码22 项目: webarchive-commons   文件: GZIPMemberSeriesTest.java
public void testDouble() throws IndexOutOfBoundsException, FileNotFoundException, IOException {

		InputStream is = getClass().getResourceAsStream("abcd.gz");
		byte abcd[] = ByteStreams.toByteArray(is);
		byte abcd2[] = ByteOp.append(abcd, abcd);
		ByteArrayInputStream bais = new ByteArrayInputStream(abcd2);
		Stream stream = new SimpleStream(bais);
		GZIPMemberSeries s = new GZIPMemberSeries(stream, "unk", 0);
		GZIPSeriesMember m = s.getNextMember();
		assertNotNull(m);
		assertEquals(0,m.getRecordStartOffset());
		assertEquals(10,m.getCompressedBytesRead());
		TestUtils.assertStreamEquals(m,"abcd".getBytes(IAUtils.UTF8));

		m = s.getNextMember();
		assertNotNull(m);
		assertEquals(abcd.length,m.getRecordStartOffset());
		assertEquals(10,m.getCompressedBytesRead());
		TestUtils.assertStreamEquals(m,"abcd".getBytes(IAUtils.UTF8));
		assertNull(s.getNextMember());
	}
 
源代码23 项目: Parties   文件: PartiesPacket.java
public static PartiesPacket read(ADPPlugin plugin, byte[] bytes) {
	PartiesPacket ret = null;
	try {
		ByteArrayDataInput input = ByteStreams.newDataInput(bytes);
		String foundVersion = input.readUTF();
		
		if (foundVersion.equals(plugin.getVersion())) {
			PartiesPacket packet = new PartiesPacket(foundVersion);
			packet.type = PacketType.valueOf(input.readUTF());
			packet.partyName = input.readUTF();
			packet.playerUuid = UUID.fromString(input.readUTF());
			packet.payload = input.readUTF();
			ret = packet;
		} else {
			plugin.getLoggerManager().printError(Constants.DEBUG_LOG_MESSAGING_FAILED_VERSION
					.replace("{current}", plugin.getVersion())
					.replace("{version}", foundVersion));
		}
	} catch (Exception ex) {
		plugin.getLoggerManager().printError(Constants.DEBUG_LOG_MESSAGING_FAILED_READ
				.replace("{message}", ex.getMessage()));
	}
	return ret;
}
 
源代码24 项目: apkfile   文件: ResourceString.java
/**
 * Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string.
 * Strings are prefixed by 2 values. The first is the number of characters in the string.
 * The second is the encoding length (number of bytes in the string).
 *
 * <p>Here's an example UTF-8-encoded string of ab©:
 * <pre>03 04 61 62 C2 A9 00</pre>
 *
 * @param str  The string to be encoded.
 * @param type The encoding type that the {@link ResourceString} should be encoded in.
 * @return The encoded string.
 */
public static byte[] encodeString(String str, Type type) {
    byte[] bytes = str.getBytes(type.charset());
    // The extra 5 bytes is for metadata (character count + byte count) and the NULL terminator.
    ByteArrayDataOutput output = ByteStreams.newDataOutput(bytes.length + 5);
    encodeLength(output, str.length(), type);
    if (type == Type.UTF8) {  // Only UTF-8 strings have the encoding length.
        encodeLength(output, bytes.length, type);
    }
    output.write(bytes);
    // NULL-terminate the string
    if (type == Type.UTF8) {
        output.write(0);
    } else {
        output.writeShort(0);
    }
    return output.toByteArray();
}
 
源代码25 项目: imhotep   文件: SquallArchiveWriter.java
private void internalAppendFile(FSDataOutputStream os, File file, List<String> parentDirectories, SquallArchiveCompressor compressor, String archiveFilename) throws IOException {
    final String baseFilename = file.getName().replaceAll("\\s+", "_");
    final String filename = makeFilename(parentDirectories, baseFilename);
    final long size = file.length();
    final long timestamp = file.lastModified();
    final long startOffset = os.getPos();

    final InputStream is = new BufferedInputStream(new FileInputStream(file));
    final String checksum;
    try {
        final CompressionOutputStream cos = compressor.newOutputStream(os);
        final DigestOutputStream dos = new DigestOutputStream(cos, ArchiveUtils.getMD5Digest());
        ByteStreams.copy(is, dos);
        checksum = ArchiveUtils.toHex(dos.getMessageDigest().digest());
        cos.finish();
    } finally {
        is.close();
    }

    pendingMetadataWrites.add(new FileMetadata(filename, size, timestamp, checksum, startOffset, compressor, archiveFilename));
}
 
源代码26 项目: Indra   文件: VectorIterator.java
private void setCurrentContent() throws IOException {
    if (numberOfVectors > 0) {
        numberOfVectors--;

        ByteArrayDataOutput out = ByteStreams.newDataOutput();

        byte b;
        while ((b = input.readByte()) != ' ') {
            out.writeByte(b);
        }

        String word = new String(out.toByteArray(), StandardCharsets.UTF_8);
        if (this.sparse) {
            this.currentVector = new TermVector(true, word, readSparseVector(this.dimensions));
        } else {
            this.currentVector = new TermVector(false, word, readDenseVector(this.dimensions));
        }

    } else {
        this.currentVector = null;
    }
}
 
源代码27 项目: imhotep   文件: TestMemoryFlamdex.java
@Test
public void testIntMaxValue() throws IOException {
    MemoryFlamdex fdx = new MemoryFlamdex().setNumDocs(1);
    IntFieldWriter ifw = fdx.getIntFieldWriter("if1");
    ifw.nextTerm(Integer.MAX_VALUE);
    ifw.nextDoc(0);
    ifw.close();
    fdx.close();

    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    fdx.write(out);

    MemoryFlamdex fdx2 = new MemoryFlamdex();
    fdx2.readFields(ByteStreams.newDataInput(out.toByteArray()));

    innerTestIntMaxValue(fdx2);

    innerTestIntMaxValue(MemoryFlamdex.streamer(ByteStreams.newDataInput(out.toByteArray())));
}
 
源代码28 项目: buck   文件: XctoolRunTestsStep.java
@Override
public void run() {
  try (OutputStream outputStream = filesystem.newFileOutputStream(outputPath);
      TeeInputStream stdoutWrapperStream =
          new TeeInputStream(launchedProcess.getStdout(), outputStream)) {
    if (stdoutReadingCallback.isPresent()) {
      // The caller is responsible for reading all the data, which TeeInputStream will
      // copy to outputStream.
      stdoutReadingCallback.get().readStdout(stdoutWrapperStream);
    } else {
      // Nobody's going to read from stdoutWrapperStream, so close it and copy
      // the process's stdout to outputPath directly.
      stdoutWrapperStream.close();
      ByteStreams.copy(launchedProcess.getStdout(), outputStream);
    }
  } catch (IOException e) {
    exception = Optional.of(e);
  }
}
 
源代码29 项目: selenium   文件: Contents.java
public static byte[] bytes(Supplier<InputStream> supplier) {
  Require.nonNull("Supplier of input", supplier);

  try (InputStream is = supplier.get();
       ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
    ByteStreams.copy(is, bos);
    return bos.toByteArray();
  } catch (IOException e) {
    throw new UncheckedIOException(e);
  }
}
 
源代码30 项目: big-c   文件: TestTools.java
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);
  }
}