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


Java StreamHelper类代码示例

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


StreamHelper类属于com.helger.commons.io.stream包,在下文中一共展示了StreamHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: STXCharStream

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
private STXCharStream (@Nonnull final Reader aReader,
                       @Nonnegative final int nStartLine,
                       @Nonnegative final int nStartColumn,
                       @Nonnegative final int nBufferSize)
{
  ValueEnforcer.isGE0 (nBufferSize, "BufferSize");
  // Using a buffered reader gives a minimal speedup
  m_aReader = StreamHelper.getBuffered (ValueEnforcer.notNull (aReader, "Reader"));
  m_nLine = ValueEnforcer.isGE0 (nStartLine, "StartLine");
  m_nColumn = ValueEnforcer.isGE0 (nStartColumn, "StartColumn") - 1;

  m_nAvailable = nBufferSize;
  m_nBufsize = nBufferSize;
  m_aBuffer = new char [nBufferSize];
  m_aBufLine = new int [nBufferSize];
  m_aBufColumn = new int [nBufferSize];
  m_aNextCharBuf = new char [DEFAULT_BUF_SIZE];
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:19,代码来源:STXCharStream.java

示例3: close

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
public void close () throws IOException
{
  // Avoid double closing
  if (!m_aClosing.getAndSet (true))
  {
    m_aLock.lock ();
    try
    {
      // Start closing
      StreamHelper.close (m_aIndexReader);

      // Ensure to commit the writer in case of pending changes
      if (m_aIndexWriter != null && m_aIndexWriter.isOpen ())
        m_aIndexWriter.commit ();
      StreamHelper.close (m_aIndexWriter);
      StreamHelper.close (m_aDir);
      s_aLogger.info ("Closed Lucene reader/writer/directory");
    }
    finally
    {
      m_aLock.unlock ();
    }
  }
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:25,代码来源:PDLucene.java

示例4: write

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
/**
 * Write the passed object to an {@link OutputStream}.
 *
 * @param aObject
 *        The object to be written. May not be <code>null</code>.
 * @param aOS
 *        The output stream to write to. Will always be closed. May not be
 *        <code>null</code>.
 * @return {@link ESuccess}
 */
@Nonnull
default ESuccess write (@Nonnull final JAXBTYPE aObject, @Nonnull @WillClose final OutputStream aOS)
{
  try
  {
    if (USE_JAXB_CHARSET_FIX)
    {
      return write (aObject, SafeXMLStreamWriter.create (aOS, getXMLWriterSettings ()));
    }
    return write (aObject, TransformResultFactory.create (aOS));
  }
  finally
  {
    // Needs to be manually closed
    StreamHelper.close (aOS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:IJAXBWriter.java

示例5: read

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
/**
 * Read a document from the specified input stream. The secure reading feature
 * has affect when using this method.
 *
 * @param aIS
 *        The input stream to read. May not be <code>null</code>.
 * @return <code>null</code> in case reading fails.
 */
@Nullable
default JAXBTYPE read (@Nonnull final InputStream aIS)
{
  ValueEnforcer.notNull (aIS, "InputStream");

  final InputStreamAndCharset aISAndBOM = CharsetHelper.getInputStreamAndCharsetFromBOM (aIS);
  if (aISAndBOM.hasCharset ())
  {
    // BOM was found - read from Reader
    return read (StreamHelper.createReader (aISAndBOM.getInputStream (), aISAndBOM.getCharset ()));
  }

  // No BOM found - use the returned InputStream anyway, so that the pushed
  // back bytes are read
  return read (InputSourceFactory.create (aISAndBOM.getInputStream ()));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:25,代码来源:IJAXBReader.java

示例6: getGraphAsImageWithGraphVizNeato

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
/**
 * Invoked the external process "neato" from the GraphViz package. Attention:
 * this spans a sub-process!
 *
 * @param sFileType
 *        The file type to be generated. E.g. "png" - see neato help for
 *        details. May neither be <code>null</code> nor empty.
 * @param sDOT
 *        The DOT file to be converted to an image. May neither be
 *        <code>null</code> nor empty.
 * @return The byte buffer that keeps the converted image. Never
 *         <code>null</code>.
 * @throws IOException
 *         In case some IO error occurs
 * @throws InterruptedException
 *         If the sub-process did not terminate correctly!
 */
@Nonnull
public static NonBlockingByteArrayOutputStream getGraphAsImageWithGraphVizNeato (@Nonnull @Nonempty final String sFileType,
                                                                                 @Nonnull final String sDOT) throws IOException,
                                                                                                             InterruptedException
{
  ValueEnforcer.notEmpty (sFileType, "FileType");
  ValueEnforcer.notEmpty (sDOT, "DOT");

  final ProcessBuilder aPB = new ProcessBuilder ("neato", "-T" + sFileType).redirectErrorStream (false);
  final Process p = aPB.start ();
  // Set neato stdin
  p.getOutputStream ().write (sDOT.getBytes (StandardCharsets.UTF_8));
  p.getOutputStream ().close ();
  // Read neato stdout
  final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ();
  StreamHelper.copyInputStreamToOutputStream (p.getInputStream (), aBAOS);
  p.waitFor ();
  return aBAOS;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:37,代码来源:GraphVizHelper.java

示例7: readMicroXML

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
@Nullable
public static IMicroDocument readMicroXML (@WillClose @Nullable final InputStream aIS,
                                           @Nullable final ISAXReaderSettings aSettings)
{
  if (aIS == null)
    return null;

  try
  {
    return readMicroXML (InputSourceFactory.create (aIS), aSettings);
  }
  finally
  {
    StreamHelper.close (aIS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:17,代码来源:MicroReader.java

示例8: writeToWriter

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
/**
 * Write a Micro Node to a {@link Writer}.
 *
 * @param aNode
 *        The node to be serialized. May be any kind of node (incl.
 *        documents). May not be <code>null</code>.
 * @param aWriter
 *        The writer to write to. May not be <code>null</code>. The writer is
 *        closed anyway directly after the operation finishes (on success and
 *        on error).
 * @param aSettings
 *        The settings to be used for the creation. May not be
 *        <code>null</code>.
 * @return {@link ESuccess}
 */
@Nonnull
public static ESuccess writeToWriter (@Nonnull final IMicroNode aNode,
                                      @Nonnull @WillClose final Writer aWriter,
                                      @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aWriter, "Writer");
  ValueEnforcer.notNull (aSettings, "Settings");

  try
  {
    final MicroSerializer aSerializer = new MicroSerializer (aSettings);
    aSerializer.write (aNode, aWriter);
    return ESuccess.SUCCESS;
  }
  finally
  {
    StreamHelper.close (aWriter);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:36,代码来源:MicroWriter.java

示例9: writeMap

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
/**
 * Write the passed map to the passed output stream using the predefined XML
 * layout.
 *
 * @param aMap
 *        The map to be written. May not be <code>null</code>.
 * @param aOS
 *        The output stream to write to. The stream is closed independent of
 *        success or failure. May not be <code>null</code>.
 * @return {@link ESuccess#SUCCESS} when everything went well,
 *         {@link ESuccess#FAILURE} otherwise.
 */
@Nonnull
public static ESuccess writeMap (@Nonnull final Map <String, String> aMap, @Nonnull @WillClose final OutputStream aOS)
{
  ValueEnforcer.notNull (aMap, "Map");
  ValueEnforcer.notNull (aOS, "OutputStream");

  try
  {
    final IMicroDocument aDoc = createMapDocument (aMap);
    return MicroWriter.writeToStream (aDoc, aOS, XMLWriterSettings.DEFAULT_XML_SETTINGS);
  }
  finally
  {
    StreamHelper.close (aOS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:29,代码来源:XMLMapHandler.java

示例10: writeList

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
/**
 * Write the passed collection to the passed output stream using the
 * predefined XML layout.
 *
 * @param aCollection
 *        The map to be written. May not be <code>null</code>.
 * @param aOS
 *        The output stream to write to. The stream is closed independent of
 *        success or failure. May not be <code>null</code>.
 * @return {@link ESuccess#SUCCESS} when everything went well,
 *         {@link ESuccess#FAILURE} otherwise.
 */
@Nonnull
public static ESuccess writeList (@Nonnull final Collection <String> aCollection,
                                  @Nonnull @WillClose final OutputStream aOS)
{
  ValueEnforcer.notNull (aCollection, "Collection");
  ValueEnforcer.notNull (aOS, "OutputStream");

  try
  {
    final IMicroDocument aDoc = createListDocument (aCollection);
    return MicroWriter.writeToStream (aDoc, aOS, XMLWriterSettings.DEFAULT_XML_SETTINGS);
  }
  finally
  {
    StreamHelper.close (aOS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:30,代码来源:XMLListHandler.java

示例11: readFromStream

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
/**
 * Read the Json from the passed {@link InputStream}.
 *
 * @param aIS
 *        The input stream to use. May not be <code>null</code>.
 * @param aFallbackCharset
 *        The charset to be used in case no BOM is present. May not be
 *        <code>null</code>.
 * @param aCustomExceptionCallback
 *        An optional custom exception handler that can be used to collect the
 *        unrecoverable parsing errors. May be <code>null</code>.
 * @return <code>null</code> if reading failed, the Json declarations
 *         otherwise.
 */
@Nullable
public static IJson readFromStream (@Nonnull final InputStream aIS,
                                    @Nonnull final Charset aFallbackCharset,
                                    @Nullable final IJsonParseExceptionCallback aCustomExceptionCallback)
{
  ValueEnforcer.notNull (aIS, "InputStream");
  ValueEnforcer.notNull (aFallbackCharset, "FallbackCharset");

  try
  {
    final Reader aReader = CharsetHelper.getReaderByBOM (aIS, aFallbackCharset);
    return _readJson (aReader, aCustomExceptionCallback);
  }
  finally
  {
    StreamHelper.close (aIS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:33,代码来源:JsonReader.java

示例12: CSSCharStream

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
private CSSCharStream (@Nonnull final Reader aReader,
                       @Nonnegative final int nStartLine,
                       @Nonnegative final int nStartColumn,
                       @Nonnegative final int nBufferSize)
{
  ValueEnforcer.isGE0 (nBufferSize, "BufferSize");
  // Using a buffered reader gives a minimal speedup
  m_aReader = StreamHelper.getBuffered (ValueEnforcer.notNull (aReader, "Reader"));
  m_nLine = ValueEnforcer.isGE0 (nStartLine, "StartLine");
  m_nColumn = ValueEnforcer.isGE0 (nStartColumn, "StartColumn") - 1;

  m_nAvailable = nBufferSize;
  m_nBufsize = nBufferSize;
  m_aBuffer = new char [nBufferSize];
  m_aBufLine = new int [nBufferSize];
  m_aBufColumn = new int [nBufferSize];
  m_aNextCharBuf = new char [DEFAULT_BUF_SIZE];
}
 
开发者ID:phax,项目名称:ph-css,代码行数:19,代码来源:CSSCharStream.java

示例13: _convert

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
@Nonnull
private static ByteBuffer _convert (@Nonnull @WillClose final ReadableByteChannel aChannel) throws IOException
{
  try
  {
    final ByteBuffer buf = ByteBuffer.allocate (1024);
    final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ();
    final WritableByteChannel aOutChannel = Channels.newChannel (aBAOS);
    while (aChannel.read (buf) > 0)
    {
      buf.flip ();
      aOutChannel.write (buf);
    }
    return ByteBuffer.wrap (aBAOS.toByteArray ());
  }
  finally
  {
    StreamHelper.close (aChannel);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:21,代码来源:CodepointIteratorReadableByteChannel.java

示例14: loadProperties

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
@Nullable
public static NonBlockingProperties loadProperties (@Nonnull @WillClose final Reader aReader)
{
  ValueEnforcer.notNull (aReader, "Reader");

  final Reader aBufferedReader = StreamHelper.getBuffered (aReader);
  try
  {
    final NonBlockingProperties aProps = new NonBlockingProperties ();
    aProps.load (aBufferedReader);
    return aProps;
  }
  catch (final IOException ex)
  {
    return null;
  }
  finally
  {
    StreamHelper.close (aBufferedReader);
    StreamHelper.close (aReader);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:PropertiesHelper.java

示例15: decode

import com.helger.commons.io.stream.StreamHelper; //导入依赖的package包/类
public void decode (@Nullable final byte [] aEncodedBuffer,
                    @Nonnegative final int nOfs,
                    @Nonnegative final int nLen,
                    @Nonnull @WillNotClose final OutputStream aOS)
{
  if (aEncodedBuffer == null || nLen == 0)
    return;

  try (final GZIPInputStream aDecodeIS = new GZIPInputStream (new NonBlockingByteArrayInputStream (aEncodedBuffer,
                                                                                                   nOfs,
                                                                                                   nLen)))
  {
    if (StreamHelper.copyInputStreamToOutputStream (aDecodeIS, aOS).isFailure ())
      throw new DecodeException ("Failed to GZIP decode!");
  }
  catch (final IOException ex)
  {
    throw new DecodeException ("Failed to GZIP encode", ex);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:21,代码来源:GZIPCodec.java


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