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


Java ByteArrayInputStream.close方法代码示例

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


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

示例1: certificateReadIsDoneSynchronously

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void certificateReadIsDoneSynchronously()
    throws ExecutionException, InterruptedException, IOException {
  MockTokenServerTransport transport = new MockTokenServerTransport();
  transport.addServiceAccount(ServiceAccount.EDITOR.getEmail(), ACCESS_TOKEN);

  ByteArrayInputStream inputStream =
      new ByteArrayInputStream(
          ServiceAccount.EDITOR.asString().getBytes(Charset.defaultCharset()));

  FirebaseCredential credential =
      FirebaseCredentials.fromCertificate(inputStream, transport, Utils.getDefaultJsonFactory());

  Assert.assertEquals(0, inputStream.available());
  inputStream.close();

  Assert.assertNotNull(((BaseCredential) credential).getGoogleCredentials());
  Assert.assertEquals(ACCESS_TOKEN, Tasks.await(credential.getAccessToken()).getAccessToken());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:20,代码来源:FirebaseCredentialsTest.java

示例2: convertBytesToObject

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public static Object convertBytesToObject(byte[] input) throws IOException, ClassNotFoundException
{
    ByteArrayInputStream bis = new ByteArrayInputStream(input);
    FixedInflaterInputStream zis = null;
    Object result = null;
    try
    {
        zis = new FixedInflaterInputStream(bis);
        ObjectInputStream ois = new ObjectInputStream(zis);
        result = ois.readObject();
        ois.close();
        zis.finish();
        zis.close();
        zis = null;
        bis.close();
    }
    finally
    {
        if (zis != null)
        {
            zis.finish();
        }
    }
    return result;
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:26,代码来源:ByteUtils.java

示例3: readSafely

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/** Reads an object from the given object input.
* The object had to be saved by the {@link NbObjectOutputStream#writeSafely} method.
*
* @param oi object input
* @return the read object
* @exception IOException if IO error occured
* @exception SafeException if the operation failed but the stream is ok
*    for further reading
*/
public static Object readSafely(ObjectInput oi) throws IOException {
    int size = oi.readInt();
    byte[] byteArray = new byte[size];
    oi.readFully(byteArray, 0, size);

    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
        NbObjectInputStream ois = new NbObjectInputStream(bis);
        Object obj = ois.readObject();
        bis.close();

        return obj;
    } catch (Exception exc) {
        // encapsulate all exceptions into safe exception
        throw new SafeException(exc);
    } catch (LinkageError le) {
        throw new SafeException(new InvocationTargetException(le));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:NbObjectInputStream.java

示例4: testWriteZeroLength

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void testWriteZeroLength() throws Exception {
    final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
    final Path container = new OneDriveHomeFinderFeature(session).find();
    final byte[] content = RandomUtils.nextBytes(0);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    assertEquals(content.length, IOUtils.copyLarge(in, out));
    in.close();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:23,代码来源:OneDriveWriteFeatureTest.java

示例5: byteArrayToObject

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
 * 
 * 功能描述:自己数组转换成对象 <br>
 * 〈功能详细描述〉
 *
 * @param bytes bytes
 * @return object
 * @throws IOException ioexception
 * @see [相关类/方法](可选)
 * @since [产品/模块版本](可选)
 */
public static Object byteArrayToObject(byte[] bytes) throws IOException {
    if (bytes == null || bytes.length <= 0) {
        return null;
    }
    Object obj = null;
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(bis));
        obj = ois.readObject();
        bis.close();
        ois.close();
    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
    }
    return obj;
}
 
开发者ID:ningyu1,项目名称:jodis-client,代码行数:28,代码来源:CacheUtils.java

示例6: byteArrayToObject

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
 * 
 * 功能描述:自己数组转换成对象 <br>
 * 〈功能详细描述〉
 * 
 * @param bytes
 *            bytes
 * @return object
 * @throws IOException
 *             ioexception
 * @see [相关类/方法](可选)
 * @since [产品/模块版本](可选)
 */
public static Object byteArrayToObject(byte[] bytes) throws IOException {
    if (bytes == null || bytes.length <= 0) {
        return null;
    }
    Object obj = null;
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(bis));
        obj = ois.readObject();
        bis.close();
        ois.close();
    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
    }
    return obj;
}
 
开发者ID:ningyu1,项目名称:redis-client,代码行数:30,代码来源:CacheUtils.java

示例7: testWrite

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void testWrite() throws Exception {
    final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
    final Path container = new OneDriveHomeFinderFeature(session).find();
    final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final byte[] buffer = new byte[32 * 1024];
    assertEquals(content.length, IOUtils.copyLarge(in, out, buffer));
    in.close();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:24,代码来源:OneDriveWriteFeatureTest.java

示例8: AvsSpeakItem

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public AvsSpeakItem(String token, String cid, ByteArrayInputStream audio) throws IOException {
    this(token, cid, IOUtils.toByteArray(audio));
    audio.close();
}
 
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:5,代码来源:AvsSpeakItem.java

示例9: unmarshalJsonStringObject

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
protected SelectServer unmarshalJsonStringObject(String jsonStringObject) throws java.io.IOException {
    MessageBodyReader<SelectServer> messageBodyReader = getJsonMessageBodyReader();
    ByteArrayInputStream bais = new ByteArrayInputStream(jsonStringObject.getBytes());
    SelectServer responseObject = messageBodyReader.readFrom(SelectServer.class, SelectServer.class, SelectServer.class.getAnnotations(), null, null, bais);
    bais.close();
    return responseObject;
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:8,代码来源:SelectServerTemplate.java

示例10: testStreamNormal

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void testStreamNormal() throws Exception {
  String value = "abc";
  ByteArrayOutputStream os = new ByteArrayOutputStream();

  pp.encodeResponse(os, value);
  Assert.assertEquals("\"abc\"", os.toString(StandardCharsets.UTF_8.name()));

  ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
  Object result = pp.decodeResponse(is, stringType);
  Assert.assertEquals(value, result);

  os.close();
  is.close();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:16,代码来源:TestProduceJsonProcessor.java

示例11: testWriteZeroLength

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void testWriteZeroLength() throws Exception {
    final B2Session session = new B2Session(
            new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
                    new Credentials(
                            System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")
                    )));
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final B2LargeUploadWriteFeature feature = new B2LargeUploadWriteFeature(session);
    final Path container = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final byte[] content = RandomUtils.nextBytes(0);
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final StatusOutputStream<VersionId> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    assertEquals(content.length, IOUtils.copyLarge(in, out));
    in.close();
    out.close();
    assertNotNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new B2ReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:30,代码来源:B2LargeUploadWriteFeatureTest.java

示例12: getEncoding

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
private String getEncoding () throws IOException {
    byte[] arr = buffer.array();
    ByteArrayInputStream in = new ByteArrayInputStream (arr);
    try {
        return EncodingUtil.detectEncoding(in);
    }            
    finally {
        in.close();                
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:XmlFileEncodingQueryImpl.java

示例13: getEncoding

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
private String getEncoding () throws IOException {
    byte[] arr = buffer.array();
    ByteArrayInputStream in = new ByteArrayInputStream (arr);
    try {
        return getFileEncoding(in);
    }
    finally {
        in.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:HtmlDataObject.java

示例14: testWriteZeroLength

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void testWriteZeroLength() throws Exception {
    final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(
            System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret")
    ));
    final SwiftSession session = new SwiftSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final SwiftRegionService regionService = new SwiftRegionService(session);
    final SwiftLargeUploadWriteFeature feature = new SwiftLargeUploadWriteFeature(session, regionService,
            new SwiftSegmentService(session, ".segments-test/"));
    final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final byte[] content = RandomUtils.nextBytes(0);
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<List<StorageObject>> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    assertEquals(content.length, IOUtils.copyLarge(in, out));
    in.close();
    out.close();
    assertNotNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new SwiftReadFeature(session, regionService).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new SwiftDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:31,代码来源:SwiftLargeUploadWriteFeatureTest.java

示例15: syncMessage

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


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