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


Java StreamHelper.getAllBytes方法代码示例

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


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

示例1: testCompressionStandalone

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testCompressionStandalone () throws IOException
{
  final byte [] aSrc = StreamHelper.getAllBytes (ClassPathResource.getInputStream ("SOAPBodyPayload.xml"));
  assertNotNull (aSrc);

  // Compression
  final NonBlockingByteArrayOutputStream aCompressedOS = new NonBlockingByteArrayOutputStream ();
  _compressPayload (new NonBlockingByteArrayInputStream (aSrc), aCompressedOS);
  final byte [] aCompressed = aCompressedOS.toByteArray ();

  // DECOMPRESSION
  final NonBlockingByteArrayOutputStream aDecompressedOS = new NonBlockingByteArrayOutputStream ();
  _decompressPayload (new NonBlockingByteArrayInputStream (aCompressed), aDecompressedOS);
  final byte [] aDecompressed = aDecompressedOS.toByteArray ();

  assertArrayEquals (aSrc, aDecompressed);
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:19,代码来源:EAS4CompressionModeFuncTest.java

示例2: testGetInputStream

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
@Ignore ("Works only when being online")
public void testGetInputStream ()
{
  try
  {
    final InputStream aIS = URLHelper.getInputStream (new URL ("http://www.orf.at"), 3000, -1, null, null);
    final byte [] aContent = StreamHelper.getAllBytes (aIS);
    s_aLogger.info ("Read " + aContent.length + " bytes");
  }
  catch (final Throwable t)
  {
    // ignore
    s_aLogger.info ("Failed to GET: " + t.getMessage ());
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:17,代码来源:URLHelperTest.java

示例3: testAccess

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testAccess ()
{
  FileSystemResource fr = new FileSystemResource ("pom.xml");
  assertTrue (fr.exists ());
  assertTrue (fr.getResourceID ().endsWith ("pom.xml"));
  assertTrue (fr.getPath ().endsWith ("pom.xml"));
  StreamHelper.close (fr.getReader (StandardCharsets.ISO_8859_1));
  final byte [] aBytes = StreamHelper.getAllBytes (fr);
  assertTrue (aBytes.length > 0);
  assertNotNull (fr.getAsURL ());
  assertNotNull (fr.getAsFile ());

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (fr, new FileSystemResource ("pom.xml"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (fr, fr.getReadableCloneForPath ("pom.xml"));
  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (fr, fr.getWritableCloneForPath ("pom.xml"));
  CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (fr, new FileSystemResource ("pom.xml2"));

  fr = new FileSystemResource ("this file does not exist");
  assertFalse (fr.exists ());
  assertNull (fr.getInputStream ());
  assertNull (fr.getReader (StandardCharsets.ISO_8859_1));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:24,代码来源:FileSystemResourceTest.java

示例4: testBOM

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testBOM ()
{
  // BOM is emitted
  byte [] aBytes = StreamHelper.getAllBytes (new StringInputStreamProvider ("abc", StandardCharsets.UTF_16));
  assertArrayEquals (new byte [] { (byte) 0xfe, (byte) 0xff, 0, 'a', 0, 'b', 0, 'c' }, aBytes);

  // No BOM is emitted!
  aBytes = StreamHelper.getAllBytes (new StringInputStreamProvider ("abc", StandardCharsets.UTF_16BE));
  assertArrayEquals (new byte [] { 0, 'a', 0, 'b', 0, 'c' }, aBytes);

  // No BOM is emitted!
  aBytes = StreamHelper.getAllBytes (new StringInputStreamProvider ("abc", StandardCharsets.UTF_16LE));
  assertArrayEquals (new byte [] { 'a', 0, 'b', 0, 'c', 0 }, aBytes);

  // No BOM is emitted!
  aBytes = StreamHelper.getAllBytes (new StringInputStreamProvider ("abc", StandardCharsets.UTF_8));
  assertArrayEquals (new byte [] { 'a', 'b', 'c' }, aBytes);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:20,代码来源:StringInputStreamProviderTest.java

示例5: getXObject

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Override
@Nonnull
protected PDImageXObject getXObject (@Nonnull final PagePreRenderContext aCtx) throws IOException
{
  // The input stream is only sometimes closed automatically
  final InputStream aIS = m_aIIS.getInputStream ();
  if (aIS == null)
    throw new IOException ("Failed to open InputStream from " + m_aIIS);

  try (final InputStream aRealIS = aIS)
  {
    final byte [] aBytes = StreamHelper.getAllBytes (aRealIS);
    switch (getImageType ())
    {
      case CCITT:
        return CCITTFactory.createFromByteArray (aCtx.getDocument (), aBytes);
      case JPEG:
        return JPEGFactory.createFromByteArray (aCtx.getDocument (), aBytes);
      case LOSSLESS:
        // API does not support it
        throw new IllegalStateException ("Lossless images cannot be read from Stream - use the version with BufferedImage!");
      default:
        throw new IllegalStateException ("Unsupported image type: " + toString ());
    }
  }
}
 
开发者ID:phax,项目名称:ph-pdf-layout,代码行数:27,代码来源:PLStreamImage.java

示例6: testCompressionModes

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testCompressionModes () throws IOException
{
  final byte [] aSrc = StreamHelper.getAllBytes (ClassPathResource.getInputStream ("SOAPBodyPayload.xml"));
  assertNotNull (aSrc);

  for (final EAS4CompressionMode eMode : EAS4CompressionMode.values ())
  {
    // Compression
    final NonBlockingByteArrayOutputStream aCompressedOS = new NonBlockingByteArrayOutputStream ();
    try (final InputStream aIS = new NonBlockingByteArrayInputStream (aSrc);
         final OutputStream aOS = eMode.getCompressStream (aCompressedOS))
    {
      StreamHelper.copyInputStreamToOutputStream (aIS, aOS);
    }
    final byte [] aCompressed = aCompressedOS.toByteArray ();

    // DECOMPRESSION
    final NonBlockingByteArrayOutputStream aDecompressedOS = new NonBlockingByteArrayOutputStream ();
    try (final InputStream aIS = eMode.getDecompressStream (new NonBlockingByteArrayInputStream (aCompressed));
         final OutputStream aOS = aDecompressedOS)
    {
      StreamHelper.copyInputStreamToOutputStream (aIS, aOS);
    }
    final byte [] aDecompressed = aDecompressedOS.toByteArray ();

    assertArrayEquals (aSrc, aDecompressed);
  }
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:30,代码来源:EAS4CompressionModeFuncTest.java

示例7: _readXML

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Nonnull
private static Document _readXML (@Nonnull final InputStream aRequestIS) throws SAXException
{
  if (isDebug ())
  {
    final byte [] aBytes = StreamHelper.getAllBytes (aRequestIS);
    final Charset aCharset = Charset.defaultCharset ();
    s_aLogger.info ("GOT[" + aCharset.name () + "]:\n" + new String (aBytes, aCharset));
    return DOMReader.readXMLDOM (aBytes);
  }
  return DOMReader.readXMLDOM (aRequestIS);
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:13,代码来源:AS4Handler.java

示例8: handleEntity

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Override
@Nonnull
public PD1BusinessCardType handleEntity (@Nonnull final HttpEntity aEntity) throws IOException
{
  // Read the payload
  final ContentType aContentType = ContentType.getOrDefault (aEntity);
  final Charset aCharset = aContentType.getCharset ();
  final byte [] aData = StreamHelper.getAllBytes (aEntity.getContent ());

  // Read version 1
  final PD1BusinessCardMarshaller aMarshaller1 = new PD1BusinessCardMarshaller ();
  if (aCharset != null)
    aMarshaller1.setCharset (aCharset);
  PD1BusinessCardType ret = aMarshaller1.read (aData);
  if (ret == null)
  {
    // Read as version 2
    final PD2BusinessCardMarshaller aMarshaller2 = new PD2BusinessCardMarshaller ();
    if (aCharset != null)
      aMarshaller2.setCharset (aCharset);
    final PD2BusinessCardType aPD2 = aMarshaller2.read (aData);
    if (aPD2 != null)
      ret = PD2BusinessCardMarshaller.getAsV1 (aPD2);
  }
  if (ret == null)
    throw new ClientProtocolException ("Malformed XML document returned from SMP server");
  return ret;
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:29,代码来源:PDSMPHttpResponseHandlerUnsigned.java

示例9: CachingTransformStreamSource

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
public CachingTransformStreamSource (@Nonnull @WillClose final InputStream aIS, @Nullable final String sSystemID)
{
  super (new NonBlockingByteArrayInputStream (StreamHelper.getAllBytes (aIS)), sSystemID);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:5,代码来源:CachingTransformStreamSource.java

示例10: _getCachedInputStream

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Nonnull
private static NonBlockingByteArrayInputStream _getCachedInputStream (@Nonnull @WillClose final InputStream aIS)
{
  return new NonBlockingByteArrayInputStream (StreamHelper.getAllBytes (aIS));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:6,代码来源:CachingSAXInputSource.java

示例11: getAllFileBytes

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
/**
 * Get the content of the file as a byte array.
 *
 * @param aFile
 *        The file to read. May be <code>null</code>.
 * @return <code>null</code> if the passed file is <code>null</code> or if the
 *         passed file does not exist.
 */
@Nullable
public static byte [] getAllFileBytes (@Nullable final File aFile)
{
  return aFile == null ? null : StreamHelper.getAllBytes (FileHelper.getInputStream (aFile));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:14,代码来源:SimpleFileIO.java


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