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


Java ByteArrayOutputStream.toByteArray方法代码示例

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


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

示例1: main

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
    RemotableInputStream remotableInputStream = new RemotableInputStream(InetAddress.getLocalHost().getHostName(), 7777, new ByteArrayInputStream("test".getBytes()));

    for (int b = -1; (b = remotableInputStream.read()) != -1;)
    {
        System.out.println((char) b);
    }

    remotableInputStream = new RemotableInputStream(InetAddress.getLocalHost().getHostName(), 7777, new ByteArrayInputStream("test".getBytes()));

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(remotableInputStream);

    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    remotableInputStream = (RemotableInputStream) ois.readObject();

    for (int b = -1; (b = remotableInputStream.read()) != -1;)
    {
        System.out.println((char) b);
    }
    remotableInputStream.close();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:RemotableInputStream.java

示例2: encryptObject

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p/>
 * Serializes and {@link #encrypt(String, AlgorithmParameters, byte[]) encrypts} the input data.
 */
@Override
public Pair<byte[], AlgorithmParameters> encryptObject(String keyAlias, AlgorithmParameters params, Object input)
{
    try
    {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(input);
        byte[] unencrypted = bos.toByteArray();
        return encrypt(keyAlias, params, unencrypted);
    }
    catch (Exception e)
    {
        throw new AlfrescoRuntimeException("Failed to serialize or encrypt object", e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:22,代码来源:AbstractEncryptor.java

示例3: testEmptyWorks

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
@Test
public void testEmptyWorks() throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  CountingOutputStream cos = new CountingOutputStream(baos);
  DataOutputStream dos = new DataOutputStream(cos);
  Codec codec = new CellCodec();
  Codec.Encoder encoder = codec.getEncoder(dos);
  encoder.flush();
  dos.close();
  long offset = cos.getCount();
  assertEquals(0, offset);
  CountingInputStream cis =
    new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
  DataInputStream dis = new DataInputStream(cis);
  Codec.Decoder decoder = codec.getDecoder(dis);
  assertFalse(decoder.advance());
  dis.close();
  assertEquals(0, cis.getCount());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:TestCellCodec.java

示例4: reproduce

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * Reproduce this.
 *
 * Generally, data is changed by pre-processors before mapping to bean object.
 * Use this to prevent unexpected change of origin fixtureMap.
 *
 * @return reproduced data
 */
public FixtureMap reproduce() {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(1024 * 2);
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(this);
        oos.flush();
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
        Object obj = ois.readObject();
        FixtureMap dup = (FixtureMap) obj;

        dup.setParent(getParent());
        dup.setRoot(isRoot());
        dup.setFixtureName(getFixtureName());

        return dup;
    } catch (Exception e) {
        throw new FixtureFormatException(getFixtureName(), e);
    }
}
 
开发者ID:keepcosmos,项目名称:beanmother,代码行数:30,代码来源:FixtureMap.java

示例5: toByteArray

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public static byte[] toByteArray(String hexData, boolean isHex) {
    if (hexData == null || hexData.equals("")) {
        return null;
    }
    if (!isHex) {
        return hexData.getBytes();
    }
    hexData = hexData.replaceAll("\\s+", "");
    String hexDigits = "0123456789ABCDEF";
    ByteArrayOutputStream baos = new ByteArrayOutputStream(
            hexData.length() / 2);
    // 将每2位16进制整数组装成一个字节
    for (int i = 0; i < hexData.length(); i += 2) {
        baos.write((hexDigits.indexOf(hexData.charAt(i)) << 4 | hexDigits
                .indexOf(hexData.charAt(i + 1))));
    }
    byte[] bytes = baos.toByteArray();
    try {
        baos.close();
    } catch (IOException e) {
        LogUtils.warn(e);
    }
    return bytes;
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:25,代码来源:ConvertUtils.java

示例6: component

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
@Override
public SummaryResponse component(Components components) throws IOException {
    if (components == null) {
        return new SummaryResponseImpl();
    }

    ObjectMapper mapper = ObjectMapperHelper.get();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    mapper.writeValue(out, components);
    ByteArrayInputStream content = new ByteArrayInputStream(out.toByteArray());

    Map<String, String> headers = new HashMap<>();
    XrayImpl.addContentTypeJsonHeader(headers);

    HttpResponse response = xray.post("summary/component", headers, content);
    return mapper.readValue(response.getEntity().getContent(), SummaryResponseImpl.class);
}
 
开发者ID:JFrogDev,项目名称:jfrog-idea-plugin,代码行数:18,代码来源:SummaryImpl.java

示例7: geometryToWKB

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private byte[] geometryToWKB(Geometry geom) throws IOException
{
	WKBWriter wkbWriter = new WKBWriter();
	ByteArrayOutputStream bytesStream = new ByteArrayOutputStream();
	wkbWriter.write(geom, new OutputStreamOutStream(bytesStream));
	byte[] geomBytes = bytesStream.toByteArray();
	bytesStream.close();

	return geomBytes;
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:11,代码来源:PostgresSQLStatisticsProvider.java

示例8: toByteArray

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * Converts the entirety of an {@link InputStream} to a byte array.
 *
 * @param inputStream the {@link InputStream} to be read. The input stream is not closed by this
 *    method.
 * @return a byte array containing all of the inputStream's bytes.
 * @throws IOException if an error occurs reading from the stream.
 */
public static byte[] toByteArray(InputStream inputStream) throws IOException {
  byte[] buffer = new byte[1024 * 4];
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  int bytesRead;
  while ((bytesRead = inputStream.read(buffer)) != -1) {
    outputStream.write(buffer, 0, bytesRead);
  }
  return outputStream.toByteArray();
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:18,代码来源:Util.java

示例9: compress

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * Compresses a given String. It is encoded using ISO-8859-1, So any decompression of the
 * compressed string should also use ISO-8859-1
 * 
 * @param str String to be compressed.
 * @return compressed bytes
 * @throws IOException
 */
public static byte[] compress(String str) throws IOException {
  if (str == null || str.length() == 0) {
    return null;
  }
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  GZIPOutputStream gzip = new GZIPOutputStream(out);
  gzip.write(str.getBytes("UTF-8"));
  gzip.close();
  byte[] outBytes = out.toByteArray();
  return outBytes;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:BeanUtilFuncs.java

示例10: getStreamFromDrawable

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
protected InputStream getStreamFromDrawable(String imageUri) {
    try {
        int drawableId = Integer.parseInt(imageUri);
        BitmapDrawable drawable = (BitmapDrawable) this.context.getResources().getDrawable(drawableId);
        Bitmap bitmap = drawable.getBitmap();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 0, os);
        return new ByteArrayInputStream(os.toByteArray());
    } catch (Exception e) {
        Log.e("e", e.toString());
    }
    return null;
}
 
开发者ID:redleaf2002,项目名称:magic_imageloader_network,代码行数:14,代码来源:BaseDownloadStream.java

示例11: syncMessage

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private void syncMessage(SyncSessionFactory fromSync, ContactId fromId,
		SyncSessionFactory toSync, ContactId toId, int num, boolean valid)
		throws IOException, TimeoutException {

	// Debug output
	String from = "0";
	if (fromSync == sync1) from = "1";
	else if (fromSync == sync2) from = "2";
	String to = "0";
	if (toSync == sync1) to = "1";
	else if (toSync == sync2) to = "2";
	LOG.info("TEST: Sending message from " + from + " to " + to);

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	// Create an outgoing sync session
	SyncSession sessionFrom =
			fromSync.createSimplexOutgoingSession(toId, TestPluginConfigModule.MAX_LATENCY, out);
	// Write whatever needs to be written
	sessionFrom.run();
	out.close();

	ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
	// Create an incoming sync session
	SyncSession sessionTo = toSync.createIncomingSession(fromId, in);
	// Read whatever needs to be read
	sessionTo.run();
	in.close();

	if (valid) {
		deliveryWaiter.await(TIMEOUT, num);
	} else {
		validationWaiter.await(TIMEOUT, num);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:35,代码来源:BriarIntegrationTest.java

示例12: removeNamespace

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private String removeNamespace(String xml) throws Exception {
    NamespaceRemovingInputStream inputStream = new NamespaceRemovingInputStream(new ByteArrayInputStream(xml.getBytes()));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    IOUtils.copy(inputStream, outputStream);

    return new String(outputStream.toByteArray());
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:8,代码来源:NamespaceRemovingInputStreamTest.java

示例13: serialize

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public static <T> byte[] serialize(T obj){
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	HessianOutput ho = new HessianOutput(os);
	try {
		ho.writeObject(obj);
	} catch (IOException e) {
		throw new IllegalStateException(e.getMessage(), e);
	}
	return os.toByteArray();
}
 
开发者ID:SnailFastGo,项目名称:netty_op,代码行数:11,代码来源:HessianSerializer.java

示例14: createPullResult

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, List<MessageExt> messageExtList) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (MessageExt messageExt : messageExtList) {
        outputStream.write(MessageDecoder.encode(messageExt, false));
    }
    return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, outputStream.toByteArray());
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:8,代码来源:DefaultMQPushConsumerTest.java

示例15: deflate

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private byte[] deflate(byte[] b) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(baos);
    dos.write(b);
    dos.close();
    return baos.toByteArray();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:PNGImageWriter.java


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