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


Java StreamHelper.getAllBytesAsString方法代码示例

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


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

示例1: testExternalEntityExpansion

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testExternalEntityExpansion () throws SAXException
{
  // Include a dummy file
  final File aFile = new File ("src/test/resources/test1.txt");
  assertTrue (aFile.exists ());
  final String sFileContent = StreamHelper.getAllBytesAsString (new FileSystemResource (aFile),
                                                                StandardCharsets.ISO_8859_1);

  // The XML with XXE problem
  final String sXML = "<?xml version='1.0' encoding='utf-8'?>" +
                      "<!DOCTYPE root [" +
                      " <!ELEMENT root ANY >" +
                      " <!ENTITY xxe SYSTEM \"" +
                      FileHelper.getAsURLString (aFile) +
                      "\" >]>" +
                      "<root>&xxe;</root>";
  final DOMReaderSettings aDRS = new DOMReaderSettings ().setEntityResolver ( (publicId,
                                                                               systemId) -> InputSourceFactory.create (new URLResource (systemId)));

  // Read successful - entity expansion!
  final Document aDoc = DOMReader.readXMLDOM (sXML, aDRS);
  assertNotNull (aDoc);
  assertEquals (sFileContent, aDoc.getDocumentElement ().getTextContent ());

  // Should fail because inline DTD is present
  try
  {
    DOMReader.readXMLDOM (sXML, aDRS.getClone ().setFeatureValues (EXMLParserFeature.AVOID_XXE_SETTINGS));
    fail ();
  }
  catch (final SAXParseException ex)
  {
    // Expected
    assertTrue (ex.getMessage ().contains ("http://apache.org/xml/features/disallow-doctype-decl"));
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:38,代码来源:DOMReaderTest.java

示例2: testIssue

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testIssue ()
{
  final String css = StreamHelper.getAllBytesAsString (new FileSystemResource ("src/test/resources/testfiles/css30/good/issue35.css"),
                                                       StandardCharsets.UTF_8);
  final CSSReaderSettings aSettings = new CSSReaderSettings ().setCSSVersion (ECSSVersion.LATEST)
                                                              .setBrowserCompliantMode (false);
  final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream (css, aSettings);
  assertNotNull (cascadingStyleSheet);
  final CSSWriter writer = new CSSWriter (new CSSWriterSettings (ECSSVersion.LATEST, true));
  assertNotNull (writer.getCSSAsString (cascadingStyleSheet));
}
 
开发者ID:phax,项目名称:ph-css,代码行数:13,代码来源:Issue35Test.java

示例3: processAS4UserMessage

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Nonnull
public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final Ebms3UserMessage aUserMessage,
                                                        @Nonnull final IPMode aPMode,
                                                        @Nullable final Node aPayload,
                                                        @Nullable final ICommonsList <WSS4JAttachment> aIncomingAttachments,
                                                        @Nonnull final IAS4MessageState aState)
{
  // Needed for AS4_TA13 because we want to force a decompression failure and
  // for that to happen the stream has to be read
  {
    s_aLogger.info ("Received AS4 message:");
    s_aLogger.info ("  UserMessage: " + aUserMessage);
    s_aLogger.info ("  Payload: " +
                    (aPayload == null ? "null" : true ? "present" : XMLWriter.getNodeAsString (aPayload)));

    if (aIncomingAttachments != null)
    {
      s_aLogger.info ("  Attachments: " + aIncomingAttachments.size ());
      for (final WSS4JAttachment x : aIncomingAttachments)
      {
        s_aLogger.info ("    Attachment Content Type: " + x.getMimeType ());
        if (x.getMimeType ().startsWith ("text") || x.getMimeType ().endsWith ("/xml"))
        {
          try
          {
            final InputStream aIS = x.getSourceStream ();
            s_aLogger.info ("    Attachment Stream Class: " + aIS.getClass ().getName ());
            final String sContent = StreamHelper.getAllBytesAsString (x.getSourceStream (), x.getCharset ());
            s_aLogger.info ("    Attachment Content: " + sContent.length () + " chars");
          }
          catch (final IllegalStateException ex)
          {
            s_aLogger.warn ("    Attachment Content: CANNOT BE READ", ex);
          }
        }
      }
    }
  }

  // To test returning with a failure works as intended
  if (aUserMessage.getCollaborationInfo ().getAction ().equals (ACTION_FAILURE))
  {
    return AS4MessageProcessorResult.createFailure (ACTION_FAILURE);
  }
  return AS4MessageProcessorResult.createSuccess ();
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:47,代码来源:MockMessageProcessorCheckingStreamsSPI.java

示例4: testBasePath

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
@Test
public void testBasePath () throws IOException
{
  final IFileRelativeIO aIO = FileRelativeIO.createForCurrentDir ();
  final String sTestFile = "testfile";
  final String sTestContent = "This is the test file content";
  final String sTestFile2 = "testfile2";

  // may not exist
  assertFalse (aIO.existsFile (sTestFile));

  try
  {
    // write file
    final OutputStream aOS = aIO.getOutputStream (sTestFile);
    assertNotNull (aOS);
    aOS.write (sTestContent.getBytes (StandardCharsets.ISO_8859_1));
    assertTrue (StreamHelper.close (aOS).isSuccess ());

    // rename a to b
    assertTrue (aIO.existsFile (sTestFile));
    assertTrue (aIO.renameFile (sTestFile, sTestFile2).isSuccess ());

    // ensure only b is present
    assertFalse (aIO.existsFile (sTestFile));
    assertTrue (aIO.existsFile (sTestFile2));

    // rename back from b to a
    assertTrue (aIO.renameFile (sTestFile2, sTestFile).isSuccess ());

    // ensure only a is present
    assertTrue (aIO.existsFile (sTestFile));
    assertFalse (aIO.existsFile (sTestFile2));

    // read file
    try (final InputStream aIS = aIO.getResource (sTestFile).getInputStream ())
    {
      assertNotNull (aIS);
      final String sReadContent = StreamHelper.getAllBytesAsString (aIS, StandardCharsets.ISO_8859_1);
      assertEquals (sTestContent, sReadContent);
    }
  }
  finally
  {
    // ensure all files are gone :)
    if (aIO.existsFile (sTestFile))
      assertTrue (aIO.deleteFile (sTestFile).isSuccess ());
    if (aIO.existsFile (sTestFile2))
      assertTrue (aIO.deleteFile (sTestFile2).isSuccess ());
    assertFalse (aIO.existsFile (sTestFile));
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:53,代码来源:FileRelativeIOTest.java

示例5: getFileAsString

import com.helger.commons.io.stream.StreamHelper; //导入方法依赖的package包/类
/**
 * Get the content of the passed file as a string using the system line
 * separator. Note: the last line does not end with the passed line separator.
 *
 * @param aFile
 *        The file to read. May be <code>null</code>.
 * @param aCharset
 *        The character set to use. May not be <code>null</code>.
 * @return <code>null</code> if the file does not exist, the content
 *         otherwise.
 */
@Nullable
public static String getFileAsString (@Nullable final File aFile, @Nonnull final Charset aCharset)
{
  return aFile == null ? null : StreamHelper.getAllBytesAsString (FileHelper.getInputStream (aFile), aCharset);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:17,代码来源:SimpleFileIO.java


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