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


Java StreamHelper.close方法代码示例

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


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

示例1: 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

示例2: testWrite

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testWrite ()
{
  final File f = new File ("restest.xxx");
  try
  {
    final FileSystemResource fr = new FileSystemResource (f);
    OutputStream aOS = fr.getOutputStream (EAppend.TRUNCATE);
    assertNotNull (aOS);
    StreamHelper.close (aOS);
    aOS = fr.getOutputStream (EAppend.APPEND);
    assertNotNull (aOS);
    StreamHelper.close (aOS);

    Writer w = fr.getWriter (StandardCharsets.ISO_8859_1, EAppend.TRUNCATE);
    assertNotNull (w);
    StreamHelper.close (w);
    w = fr.getWriter (StandardCharsets.ISO_8859_1, EAppend.APPEND);
    assertNotNull (w);
    StreamHelper.close (w);
  }
  finally
  {
    FileOperations.deleteFile (f);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:27,代码来源:FileSystemResourceTest.java

示例3: testGreek

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testGreek () throws Exception
{
  final String sAlpha = "?\u03B1";
  byte [] b = sAlpha.getBytes (StandardCharsets.UTF_8);
  assertEquals (sAlpha, new String (b, StandardCharsets.UTF_8));

  b = sAlpha.getBytes (StandardCharsets.UTF_8);
  assertEquals (sAlpha, new String (b, StandardCharsets.UTF_8));

  NonBlockingBufferedReader aReader = new NonBlockingBufferedReader (new InputStreamReader (new NonBlockingByteArrayInputStream (b),
                                                                                            StandardCharsets.UTF_8));
  assertEquals (sAlpha, aReader.readLine ());
  StreamHelper.close (aReader);

  aReader = new NonBlockingBufferedReader (new InputStreamReader (new NonBlockingByteArrayInputStream (b),
                                                                  StandardCharsets.UTF_8));
  assertEquals (sAlpha, aReader.readLine ());
  StreamHelper.close (aReader);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:21,代码来源:CharsetHelperTest.java

示例4: exists

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
public boolean exists ()
{
  // 1. as file
  if (URLHelper.PROTOCOL_FILE.equals (m_aURL.getProtocol ()))
    return getAsFile ().exists ();

  // Not a file URL
  InputStream aIS = null;
  try
  {
    // 2. as stream
    aIS = getInputStream ();
    return aIS != null;
  }
  catch (final Exception ex)
  {
    // 3. no
    return false;
  }
  finally
  {
    StreamHelper.close (aIS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:25,代码来源:URLResource.java

示例5: writeSettings

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Nonnull
public ESuccess writeSettings (@Nonnull final ISettings aSettings, @Nonnull @WillClose final OutputStream aOS)
{
  ValueEnforcer.notNull (aSettings, "Settings");
  ValueEnforcer.notNull (aOS, "OutputStream");

  try
  {
    // Inside try so that OS is closed
    ValueEnforcer.notNull (aSettings, "Settings");

    // No event manager invocation on writing
    final SettingsMicroDocumentConverter <T> aConverter = new SettingsMicroDocumentConverter <> (m_aSettingsFactory);
    final IMicroDocument aDoc = new MicroDocument ();
    aDoc.appendChild (aConverter.convertToMicroElement (GenericReflection.uncheckedCast (aSettings),
                                                        getWriteNamespaceURI (),
                                                        getWriteElementName ()));

    // auto-closes the stream
    return MicroWriter.writeToStream (aDoc, aOS, m_aXWS);
  }
  finally
  {
    StreamHelper.close (aOS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:27,代码来源:SettingsPersistenceXML.java

示例6: _readWordList

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
private static ICommonsList <String> _readWordList (final IReadableResource aRes,
                                                    final Charset aCharset) throws IOException
{
  final ICommonsList <String> ret = new CommonsArrayList<> ();
  final NonBlockingBufferedReader aBR = new NonBlockingBufferedReader (new InputStreamReader (aRes.getInputStream (),
                                                                                              aCharset));
  String sLine;
  int nIdx = 0;
  while ((sLine = aBR.readLine ()) != null)
  {
    nIdx++;
    if ((nIdx % 3) == 0)
    {
      ret.add (sLine);
      if (ret.size () >= 100)
        break;
    }
  }
  StreamHelper.close (aBR);
  return ret;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:BenchmarkLevenshteinDistance.java

示例7: writeToStream

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
/**
 * Write a Micro Node to an {@link OutputStream}.
 *
 * @param aNode
 *        The node to be serialized. May be any kind of node (incl.
 *        documents). May not be <code>null</code>.
 * @param aOS
 *        The output stream to write to. May not be <code>null</code>. The
 *        output stream 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 writeToStream (@Nonnull final IMicroNode aNode,
                                      @Nonnull @WillClose final OutputStream aOS,
                                      @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aOS, "OutputStream");
  ValueEnforcer.notNull (aSettings, "Settings");

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

示例8: 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

示例9: 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

示例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: destroyHttpClient

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@After
public void destroyHttpClient ()
{
  if (m_aClient != null)
  {
    StreamHelper.close (m_aClient);
    m_aClient = null;
  }
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:10,代码来源:AbstractUserMessageTestSetUp.java

示例12: destroy

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
public static void destroy ()
{
  if (s_aWatch != null)
  {
    StreamHelper.close (s_aWatch);
    s_aWatch = null;
    s_aLogger.info ("Successfully shutdown WatchDir");
  }
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:10,代码来源:DropFolderUserMessage.java

示例13: readFromStream

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Nullable
public static STXPath readFromStream (@Nonnull final IHasInputStream aISP, @Nonnull final Charset aCharset)
{
  ValueEnforcer.notNull (aISP, "InputStreamProvider");
  ValueEnforcer.notNull (aCharset, "Charset");

  final InputStream aIS = aISP.getInputStream ();
  final Reader aReader = StreamHelper.createReader (aIS, aCharset);
  try
  {
    final STXCharStream aCharStream = new STXCharStream (aReader);

    final STXNode aNode = _readSTXPath (aCharStream);

    // Failed to interpret content as CSS?
    if (aNode == null)
      return null;

    // Convert the AST to a domain object
    final STXPath ret = STXNodeToDomainObject.convertToDomainObject (aNode);
    return ret;
  }
  finally
  {
    StreamHelper.close (aReader);
  }
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:28,代码来源:STXReader.java

示例14: onDestroy

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Override
protected void onDestroy (@Nonnull final IScope aScopeInDestruction)
{
  StreamHelper.close (m_aLucene);
  StreamHelper.close (m_aStorageMgr);
  StreamHelper.close (m_aIndexerMgr);
  StreamHelper.close (m_aHttpClientMgr);
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:9,代码来源:PDMetaManager.java

示例15: _assertNull

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
private static void _assertNull (@WillClose final InputStream aIS)
{
  try
  {
    assertNull (aIS);
  }
  finally
  {
    StreamHelper.close (aIS);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:12,代码来源:JavaClassLoaderFuncTest.java


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