當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。