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


Java ByteArrayOutputStream.toByteArray方法代码示例

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


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

示例1: getResponseEntity

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
private String getResponseEntity(HttpResponse result) throws IOException {
    HttpEntity entity = result.getEntity();
    if (entity == null) {
        log.debug("Null response entity");
        return null;
    }

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        entity.writeTo(bos);
        byte[] bytes = bos.toByteArray();
        if (bytes == null) {
            bytes = "null".getBytes();
        }
        String response = new String(bytes);
        log.debug("Response with code " + result + ": " + response);
        return response;
    } finally {
        InputStream content = entity.getContent();
        if (content != null) {
            content.close();
        }
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:25,代码来源:HttpUtils.java

示例2: copy

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * Clone  a Protostuff object
 *
 * @param t the protobuf message to copy
 * @return a deep copy of {@code t}
 */
public static <T extends Message<T>> T copy(T t) {
  try {
    Schema<T> schema = t.cachedSchema();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GraphIOUtil.writeDelimitedTo(new DataOutputStream(out), t, schema);
    // TODO: avoid array copy
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    T newMessage = schema.newMessage();
    GraphIOUtil.mergeDelimitedFrom(in, newMessage, schema);
    return newMessage;
  } catch (IOException e) {
    throw UserException.dataReadError(e)
      .message("Failure decoding object, please ensure that you ran dremio-admin upgrade on Dremio.")
      .build(logger);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:ProtostuffUtil.java

示例3: encrypt

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
@Override
byte[] encrypt(byte[] key, byte[] data) {
  try {
    SecretKeySpec keySpec = new SecretKeySpec(key, AES);
    cipher.init(Cipher.ENCRYPT_MODE, keySpec);
    byte[] ciphertext = cipher.doFinal(data);

    // Write out the metadata.
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    DataOutput out = new DataOutputStream(stream);

    byte[] params = cipher.getParameters().getEncoded();
    WritableUtils.writeVInt(out, params.length);
    out.write(params);

    // Write the original ciphertext and return the new ciphertext.
    out.write(ciphertext);
    return stream.toByteArray();
  } catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | IOException e) {
    throw new EncryptionException(e);
  }
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:23,代码来源:AESValueEncryptor.java

示例4: wrap

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
public static WarpScriptStackFunction wrap(String name, InputStream in, boolean secure) {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  
  byte[] buf = new byte[1024];

  try {
    while(true) {
      int len = in.read(buf);
      
      if (len < 0) {
        break;
      }
      
      baos.write(buf, 0, len);
    }      
    
    in.close();
    
    String mc2 = new String(baos.toByteArray(), Charsets.UTF_8);
    
    return wrap(name, mc2, secure);
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  }
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:26,代码来源:MacroHelper.java

示例5: testMixedReadLine

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
@Test
public void testMixedReadLine() throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream(1024);
    OptimizedInterceptedFileOutputStream outStream = new OptimizedInterceptedFileOutputStream(stream);
    outStream.write(new AugmentedString(1, ',', 1.5, ',', "foo", '\n'));
    outStream.write(new AugmentedString(2, ',', 2.5, ',', "bar", '\n'));
    outStream.close();

    OptimizedInterceptedFileInputStream inStream =
            new OptimizedInterceptedFileInputStream(new ByteArrayInputStream(stream.toByteArray()));

    AugmentedString line = inStream.readLine();
    assert(line.getState()[0].equals(1));
    assert(line.getState()[1].equals(1.5));
    assert(line.getState()[2].toString().equals("foo"));

    byte[] bytes = new byte[6];
    int read = inStream.read(bytes, 2, 6);
    assert(read == 6);
    assert(new String(bytes).equals("2.5,ba"));

    assert(inStream.readLine().equals("r\n"));
}
 
开发者ID:uwdb,项目名称:pipegen,代码行数:24,代码来源:InterceptedFileInputStreamTests.java

示例6: send

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
public void send(COL_RDBMS event) throws Exception {
	EncoderFactory avroEncoderFactory = EncoderFactory.get();
	SpecificDatumWriter<COL_RDBMS> avroEventWriter = new SpecificDatumWriter<COL_RDBMS>(COL_RDBMS.SCHEMA$);
	
	ByteArrayOutputStream stream = new ByteArrayOutputStream();
	BinaryEncoder binaryEncoder = avroEncoderFactory.binaryEncoder(stream,null);

	try {
		avroEventWriter.write(event, binaryEncoder);
		binaryEncoder.flush();
	} catch (IOException e) {
		e.printStackTrace();
		throw e;
	}
	IOUtils.closeQuietly(stream);

	KeyedMessage<String, byte[]> data = new KeyedMessage<String, byte[]>(
			TOPIC, stream.toByteArray());

	producer.send(data);
}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:22,代码来源:AvroRdbmsDeviceInfoPublish.java

示例7: send

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
public void send(COL_ONEM2M event) throws Exception {
	EncoderFactory avroEncoderFactory = EncoderFactory.get();
	SpecificDatumWriter<COL_ONEM2M> avroEventWriter = new SpecificDatumWriter<COL_ONEM2M>(COL_ONEM2M.SCHEMA$);
	
	ByteArrayOutputStream stream = new ByteArrayOutputStream();
	BinaryEncoder binaryEncoder = avroEncoderFactory.binaryEncoder(stream,null);

	try {
		avroEventWriter.write(event, binaryEncoder);
		binaryEncoder.flush();
	} catch (IOException e) {
		e.printStackTrace();
		throw e;
	}
	IOUtils.closeQuietly(stream);

	KeyedMessage<String, byte[]> data = new KeyedMessage<String, byte[]>(
			TOPIC, stream.toByteArray());

	producer.send(data);
}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:22,代码来源:AvroOneM2MDataPublish.java

示例8: testReadBytesOffset

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
@Test
public void testReadBytesOffset() throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream(1024);
    OptimizedInterceptedFileOutputStream outStream = new OptimizedInterceptedFileOutputStream(stream);
    outStream.write(new AugmentedString(1, ',', 1.5, ',', "foo", '\n'));
    outStream.write(new AugmentedString(2, ',', 2.5, ',', "bar", '\n'));
    outStream.close();

    OptimizedInterceptedFileInputStream inStream =
            new OptimizedInterceptedFileInputStream(new ByteArrayInputStream(stream.toByteArray()));

    byte[] bytes = new byte[6];
    int read = inStream.read(bytes, 2, 6);
    assert(read == 6);
    assert(new String(bytes).equals("1.5,fo"));

    read = inStream.read(bytes, 3, 6);
    assert(read == 6);
    assert(new String(bytes).equals(",2.5,b"));
}
 
开发者ID:uwdb,项目名称:pipegen,代码行数:21,代码来源:InterceptedFileInputStreamTests.java

示例9: downloadSettleTB

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * 结算制表下载
 * @param batch 结算批次号
 * @return
 * @throws Exception
 */
public FileTransfer downloadSettleTB(String batch) throws Exception {
	String fileName = batch + "settleTB.xls";
	File settlementFile = new File(Ryt.getParameter("SettlementFilePath") + fileName);
	if (settlementFile.exists()) {
		BufferedInputStream bis = null;
		try {
			InputStream is = new FileInputStream(settlementFile);
			ByteArrayOutputStream buffer = new ByteArrayOutputStream();
			buffer.write(is);
			return new FileTransfer(fileName, "application/x-xls", buffer.toByteArray());
		} catch (IOException e) {
			throw e;
		} finally {
			if (bis != null)
				bis.close();
		}
	} else {
		return null;
	}
}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:27,代码来源:SettlementService.java

示例10: testDisablingAutoConversionToScientificNotationInJsonStreamFormatter

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.ALL})
@Test(groups = "wso2.esb", description = "disabling auto primitive option in synapse properties ", enabled = false)
public void testDisablingAutoConversionToScientificNotationInJsonStreamFormatter() throws Exception {
    String payload =
               "{\"state\":[{\"path\":\"user_programs_progress\",\"entry\":" +
               "[{\"value\":\"false\",\"key\":\"testJson14\"}]}]}";

    HttpResponse response = httpClient.doPost("http://localhost:8280/ESBJAVA4572abc/dd",
                                              null, payload, "application/json");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    response.getEntity().writeTo(bos);
    String exPayload = new String(bos.toByteArray());
    String val = "{\"state\":[{\"path\":\"user_programs_progress\",\"entry\":" +
                 "[{\"value\":\"false\",\"key\":\"testJson14\"}]}]}";
    Assert.assertEquals(val, exPayload);
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:17,代码来源:ESBJAVA_4572TestCase.java

示例11: testReadFewerBytes

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
@Test
public void testReadFewerBytes() throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream(1024);
    OptimizedInterceptedFileOutputStream outStream = new OptimizedInterceptedFileOutputStream(stream);
    outStream.write(new AugmentedString(1, ',', 1.5, ',', "foo", '\n'));
    outStream.write(new AugmentedString(2, ',', 2.5, ',', "bar", '\n'));
    outStream.close();

    OptimizedInterceptedFileInputStream inStream =
            new OptimizedInterceptedFileInputStream(new ByteArrayInputStream(stream.toByteArray()));

    byte[] bytes = new byte[10];
    assert(inStream.read(bytes) == 10);
    assert(new String(bytes).equals("1,1.5,foo\n"));

    byte[] bytes2 = new byte[9];
    assert(inStream.read(bytes2) == 9);
    assert(new String(bytes2).equals("2,2.5,bar"));

    assert(inStream.read() != -1);
    assert(inStream.read() == -1);
}
 
开发者ID:uwdb,项目名称:pipegen,代码行数:23,代码来源:InterceptedFileInputStreamTests.java

示例12: getCurrentScreen

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
public Pair<ProcessingLifecycleStatus, byte[]> getCurrentScreen(final ProcessingLifecycleStatus status, final AssumedScreenTest screenTest) throws ApplicationDownException, IOException {
    if(!processManager.isMtgoRunningOrLoading()) {
        throw new ApplicationDownException("MTGO is not running!");
    }

    BufferedImage bi = robot.createScreenCapture(new Rectangle(0, 0, screenWidth, screenHeight));

    if(bi != null) {
        RawLines rawLines;

        if (screenTest == AssumedScreenTest.NOT_NEEDED) {
            rawLines = tesseractWrapper.getRawText(bi);
        } else {
            rawLines = tesseractWrapper.getRawText(bi, screenTest.getScreenTestBounds());
        }

        logger.info("Processing raw lines");
        final ProcessingLifecycleStatus outcomeStatus = rawLinesProcessor.determineLifecycleStatus(rawLines);
        logger.info("Determined new status: " + status.name());

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(bi, "jpg", baos);
        baos.flush();
        byte[] imageAsByteArray = baos.toByteArray();
        baos.close();

        return new ImmutablePair<>(outcomeStatus, imageAsByteArray);
    }

    throw new ApplicationDownException("Somehow made it to this unreachable point");
}
 
开发者ID:corydissinger,项目名称:mtgo-best-bot,代码行数:32,代码来源:RobotWrapper.java

示例13: createBotCamera

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
private BotCamera createBotCamera(BufferedImage image, PlayerBot remotePlayerBot) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "jpg", baos );
    baos.flush();
    byte[] imageInByte = baos.toByteArray();

    BotCamera botCamera = new BotCamera(imageInByte, new Date());
    botCamera.setPlayerBot(remotePlayerBot);
    return botCamera;
}
 
开发者ID:corydissinger,项目名称:mtgo-best-bot,代码行数:11,代码来源:RobotWrapper.java

示例14: payload

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * 将Blog对象序列化存入payload
 * 可以只将所需要的字段存入payload,这里对整个实体类进行序列化,方便以后需求,不建议采用这种方法
 */
@Override
public BytesRef payload() {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(bos);
        out.writeObject(currentBlog);
        out.close();
        BytesRef bytesRef = new BytesRef(bos.toByteArray());
        return bytesRef;
    } catch (IOException e) {
        logger.error("", e);
        return null;
    }
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:19,代码来源:BlogIterator.java

示例15: compress

import org.apache.commons.io.output.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * Compress.
 *
 * @param str the str
 * @return the byte[]
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static byte[] compress(final String str) throws IOException {
	if ((str == null) || (str.length() == 0)) {
		return null;
	}
	ByteArrayOutputStream obj = new ByteArrayOutputStream();
	GZIPOutputStream gzip = new GZIPOutputStream(obj);
	gzip.write(str.getBytes("UTF-8"));
	gzip.flush();
	gzip.close();
	return obj.toByteArray();
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:19,代码来源:GzipUtils.java


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