• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FileSystemResource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FileSystemResource类属于com.helger.commons.io.resource包,在下文中一共展示了FileSystemResource类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: create

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Nullable
public static InputSource create (@Nonnull final IReadableResource aResource)
{
  if (aResource instanceof FileSystemResource)
  {
    final File aFile = aResource.getAsFile ();
    if (aFile != null)
    {
      // Potentially use memory mapped files
      final InputSource ret = create (FileHelper.getInputStream (aFile));
      if (ret != null)
      {
        // Ensure system ID is present - may be helpful for resource
        // resolution
        final URL aURL = aResource.getAsURL ();
        if (aURL != null)
          ret.setSystemId (aURL.toExternalForm ());
      }
      return ret;
    }
  }
  return new ReadableResourceSAXInputSource (aResource);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:24,代码来源:InputSourceFactory.java


示例2: validateXMLViaPureSchematron2

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
public static boolean validateXMLViaPureSchematron2 (@Nonnull final File aSchematronFile,
                                                     @Nonnull final File aXMLFile) throws Exception
{
  // Read the schematron from file
  final PSSchema aSchema = new PSReader (new FileSystemResource (aSchematronFile)).readSchema ();
  if (!aSchema.isValid (new DoNothingPSErrorHandler ()))
    throw new IllegalArgumentException ("Invalid Schematron!");
  // Resolve the query binding to use
  final IPSQueryBinding aQueryBinding = PSQueryBindingRegistry.getQueryBindingOfNameOrThrow (aSchema.getQueryBinding ());
  // Pre-process schema
  final PSPreprocessor aPreprocessor = new PSPreprocessor (aQueryBinding);
  aPreprocessor.setKeepTitles (true);
  final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema (aSchema);
  // Bind the pre-processed schema
  final IPSBoundSchema aBoundSchema = aQueryBinding.bind (aPreprocessedSchema, null, null, null, null);
  // Read the XML file
  final Document aXMLNode = DOMReader.readXMLDOM (aXMLFile);
  if (aXMLNode == null)
    return false;
  // Perform the validation
  return aBoundSchema.validatePartially (aXMLNode, FileHelper.getAsURLString (aXMLFile)).isValid ();
}
 
开发者ID:phax,项目名称:ph-schematron,代码行数:23,代码来源:DocumentationExamples.java


示例3: validateAndProduceSVRL

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  // Create the custom parameters
  final ICommonsMap <String, Object> aCustomParameters = new CommonsHashMap <> ();
  aCustomParameters.put ("xyz", "mobile");
  aCustomParameters.put ("expected", "");

  final SchematronResourceSCH aSCH = SchematronResourceSCH.fromFile (aSchematron);

  // Assign custom parameters
  aSCH.setParameters (aCustomParameters);

  if (false)
    System.out.println (XMLWriter.getNodeAsString (aSCH.getXSLTProvider ().getXSLTDocument ()));

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
开发者ID:phax,项目名称:ph-schematron,代码行数:22,代码来源:Issue8Test.java


示例4: validateAndProduceSVRL

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@SuppressFBWarnings ("BC_IMPOSSIBLE_INSTANCEOF")
public static void validateAndProduceSVRL (final File schematron, final File xml) throws Exception
{
  final IReadableResource aSchematron = new FileSystemResource (schematron.getAbsoluteFile ());
  final IReadableResource anXMLSource = new FileSystemResource (xml.getAbsoluteFile ());
  final AbstractSchematronResource aSCH = new SchematronResourceSCH (aSchematron);
  if (aSCH instanceof SchematronResourcePure)
    ((SchematronResourcePure) aSCH).setErrorHandler (new LoggingPSErrorHandler ());
  else
    System.out.println (XMLWriter.getNodeAsString (((SchematronResourceSCH) aSCH).getXSLTProvider ()
                                                                                 .getXSLTDocument ()));
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (anXMLSource);
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
开发者ID:phax,项目名称:ph-schematron,代码行数:17,代码来源:Issue6Test.java


示例5: validateAndProduceSVRL

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception
{
  final PSSchema aSchema = new PSReader (new FileSystemResource (aSchematron)).readSchema ();
  final PSPreprocessor aPreprocessor = new PSPreprocessor (PSXPathQueryBinding.getInstance ());
  final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema (aSchema);
  final String sSCH = new PSWriter (new PSWriterSettings ().setXMLWriterSettings (new XMLWriterSettings ())).getXMLString (aPreprocessedSchema);

  if (false)
    System.out.println (sSCH);

  final SchematronResourceSCH aSCH = new SchematronResourceSCH (new ReadableResourceString (sSCH,
                                                                                            StandardCharsets.UTF_8));

  // Perform validation
  final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML));
  assertNotNull (aSVRL);
  if (false)
    System.out.println (new SVRLMarshaller ().getAsString (aSVRL));
}
 
开发者ID:phax,项目名称:ph-schematron,代码行数:20,代码来源:Issue48Test.java


示例6: main

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
public static void main (final String [] args) throws IOException
{
  s_aLogger.info ("Reading");
  final InvoiceType aInvoice = UBL21Reader.invoice ()
                                          .read (new FileSystemResource ("src/test/resources/xml/as2-test-at-gov.xml"));

  final String sNote = StringHelper.getRepeated ('X', 1024);
  final long nNotes = 2 * CGlobal.BYTES_PER_GIGABYTE / sNote.length ();
  s_aLogger.info ("Adding " + nNotes + " notes");
  for (long i = 0; i < nNotes; ++i)
    aInvoice.addNote (new NoteType (sNote));
  s_aLogger.info ("Writing");
  UBL21Writer.invoice ()
             .write (aInvoice,
                     new GZIPOutputStream (new FileSystemResource ("src/test/resources/xml/as2-test-at-gov-2gb.gz").getOutputStream (EAppend.TRUNCATE)));
  s_aLogger.info ("Done");
}
 
开发者ID:phax,项目名称:as2-peppol-client,代码行数:18,代码来源:MainCreate2GBXMLFile.java


示例7: validateXMLSchema

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
public static boolean validateXMLSchema (@Nonnull final File xsdPath, @Nonnull final File xmlPath)
{
  try
  {
    System.setProperty ("jdk.xml.maxOccurLimit", "9999999");
    final Validator aValidator = XMLSchemaCache.getInstance ().getValidator (new FileSystemResource (xsdPath));
    aValidator.validate (TransformSourceFactory.create (xmlPath));
  }
  catch (final IOException | SAXException e)
  {
    s_aLogger.info ("Exception: " + e.getMessage ());
    return false;
  }
  return true;
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:16,代码来源:XMLValidator.java


示例8: validateXMLSchematron

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
public static boolean validateXMLSchematron (@Nonnull final File schPath,
                                             @Nonnull final EMode eMode,
                                             @Nonnull final File xmlPath,
                                             @Nullable final File svrlPath)
{
  final FileSystemResource aXML = new FileSystemResource (xmlPath);
  final FileSystemResource aSCH = new FileSystemResource (schPath);

  // Use pure implementation or XSLT to do the conversion?
  final ISchematronResource aSchematron = eMode == EMode.PURE ? new SchematronResourcePure (aSCH)
                                                              : eMode == EMode.XSLT ? new SchematronResourceXSLT (aSCH)
                                                                                    : new SchematronResourceSCH (aSCH);
  final SchematronOutputType aSOT = SchematronHelper.applySchematron (aSchematron, aXML);
  if (aSOT == null)
  {
    s_aLogger.info ("Schematron file " + aSchematron + " is malformed!");
    return false;
  }

  // Write SVRL
  if (svrlPath != null)
    new SVRLMarshaller (false).write (aSOT, new FileSystemResource (svrlPath));

  final ICommonsList <SVRLFailedAssert> aFailedAsserts = SVRLHelper.getAllFailedAssertions (aSOT);
  if (aFailedAsserts.isNotEmpty ())
  {
    s_aLogger.info ("XML does not comply to Schematron!" +
                    (svrlPath != null ? " See SVRL for details: " + svrlPath : ""));
    return false;
  }

  s_aLogger.info ("XML complies to Schematron!");
  return true;
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:35,代码来源:XMLValidator.java


示例9: testBasic

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Test
public void testBasic ()
{
  final PD1BusinessCardMarshaller aMarshaller = new PD1BusinessCardMarshaller ();
  assertNotNull (aMarshaller.read (new FileSystemResource ("src/test/resources/example/v1/business-card-test1.xml")));
  assertNotNull (aMarshaller.read (new FileSystemResource ("src/test/resources/example/v1/business-card-example-spec.xml")));
  assertNotNull (aMarshaller.read (new FileSystemResource ("src/test/resources/example/v1/bc-9915-leckma.xml")));
  assertNotNull (aMarshaller.read (new FileSystemResource ("src/test/resources/example/v1/bc-0088-5033466000005.xml")));
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:10,代码来源:PD1BusinessCardMarshallerTest.java


示例10: testBasic

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Test
public void testBasic ()
{
  final PD2BusinessCardMarshaller aMarshaller = new PD2BusinessCardMarshaller ();
  assertNotNull (aMarshaller.read (new FileSystemResource ("src/test/resources/example/v2/business-card-test1.xml")));
  assertNotNull (aMarshaller.read (new FileSystemResource ("src/test/resources/example/v2/business-card-example-spec.xml")));
  assertNotNull (aMarshaller.read (new FileSystemResource ("src/test/resources/example/v2/bc-9915-leckma.xml")));
  assertNotNull (aMarshaller.read (new FileSystemResource ("src/test/resources/example/v2/bc-0088-5033466000005.xml")));
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:10,代码来源:PD2BusinessCardMarshallerTest.java


示例11: testExternalEntityExpansion

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的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


示例12: testRead

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Test
@SuppressFBWarnings (value = "NP_NONNULL_PARAM_VIOLATION")
public void testRead () throws SAXException
{
  // Read valid
  final ChangeLog aCL = ChangeLogSerializer.readChangeLog (new FileSystemResource ("src/main/resources/" +
                                                                                   CChangeLog.CHANGELOG_XML_FILENAME));
  assertNotNull (aCL);
  assertEquals (new Version (1, 0), aCL.getVersion ());
  assertEquals ("ph-xml", aCL.getComponent ());
  assertTrue (aCL.getAllEntries ().size () > 0);
  assertTrue (aCL.getAllReleases ().size () > 0);
  assertNotNull (aCL.getLatestRelease ());
  for (final EChangeLogCategory eCat : EChangeLogCategory.values ())
    assertNotNull (aCL.getAllEntriesOfCategory (eCat));

  // Read with XML Schema
  final Document aW3CDoc = DOMReader.readXMLDOM (new ClassPathResource (CChangeLog.CHANGELOG_XML_FILENAME),
                                                 new DOMReaderSettings ().setSchema (XMLSchemaCache.getInstance ()
                                                                                                   .getSchema (new ClassPathResource (CChangeLog.CHANGELOG_XSD_10))));
  assertNotNull (aW3CDoc);

  // Read invalid
  assertNull (ChangeLogSerializer.readChangeLog (null));
  assertNull (ChangeLogSerializer.readChangeLog (new ClassPathResource ("does-not-exist.xml")));

  try
  {
    aCL.getAllEntriesOfCategory (null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:35,代码来源:ChangeLogSerializerTest.java


示例13: triggerExceptionHandlersRead

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
/**
 * Trigger the registered custom exception handlers for read errors.
 *
 * @param t
 *        Thrown exception. Never <code>null</code>.
 * @param bIsInitialization
 *        <code>true</code> if this happened during initialization of a new
 *        file, <code>false</code> if it happened during regular reading.
 * @param aFile
 *        The file that was read. May be <code>null</code> for in-memory DAOs.
 */
protected static void triggerExceptionHandlersRead (@Nonnull final Throwable t,
                                                    final boolean bIsInitialization,
                                                    @Nullable final File aFile)
{
  // Custom exception handler for reading
  if (exceptionHandlersRead ().isNotEmpty ())
  {
    final IReadableResource aRes = aFile == null ? null : new FileSystemResource (aFile);
    exceptionHandlersRead ().forEach (aCB -> aCB.onDAOReadException (t, bIsInitialization, aRes));
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:AbstractWALDAO.java


示例14: triggerExceptionHandlersWrite

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
/**
 * Trigger the registered custom exception handlers for read errors.
 *
 * @param t
 *        Thrown exception. Never <code>null</code>.
 * @param sErrorFilename
 *        The filename tried to write to. Never <code>null</code>.
 * @param aDoc
 *        The XML content that should be written. May be <code>null</code> if
 *        the error occurred in XML creation.
 */
protected static void triggerExceptionHandlersWrite (@Nonnull final Throwable t,
                                                     @Nonnull final String sErrorFilename,
                                                     @Nullable final IMicroDocument aDoc)
{
  // Check if a custom exception handler is present
  if (exceptionHandlersWrite ().isNotEmpty ())
  {
    final IReadableResource aRes = new FileSystemResource (sErrorFilename);
    final String sXMLContent = aDoc == null ? "no XML document created" : MicroWriter.getNodeAsString (aDoc);
    exceptionHandlersWrite ().forEach (aCB -> aCB.onDAOWriteException (t, aRes, sXMLContent));
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:24,代码来源:AbstractWALDAO.java


示例15: _writeWALFile

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Nonnull
@MustBeLocked (ELockType.WRITE)
private ESuccess _writeWALFile (@Nonnull @Nonempty final List <DATATYPE> aModifiedElements,
                                @Nonnull final EDAOActionType eActionType,
                                @Nonnull @Nonempty final String sWALFilename)
{
  final FileSystemResource aWALRes = m_aIO.getResource (sWALFilename);
  try (final DataOutputStream aDOS = new DataOutputStream (aWALRes.getOutputStream (EAppend.APPEND)))
  {
    // Write action type ID
    StreamHelper.writeSafeUTF (aDOS, eActionType.getID ());
    // Write number of elements
    aDOS.writeInt (aModifiedElements.size ());
    // Write all data elements as XML Strings :)
    for (final DATATYPE aModifiedElement : aModifiedElements)
    {
      final String sElement = convertNativeToWALString (aModifiedElement);
      StreamHelper.writeSafeUTF (aDOS, sElement);
    }
    return ESuccess.SUCCESS;
  }
  catch (final Throwable t)
  {
    s_aLogger.error ("Error writing WAL file " + aWALRes, t);
    triggerExceptionHandlersWrite (t, sWALFilename, (IMicroDocument) null);
  }
  return ESuccess.FAILURE;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:29,代码来源:AbstractWALDAO.java


示例16: loadProperties

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Nullable
public static NonBlockingProperties loadProperties (@Nonnull final File aFile)
{
  ValueEnforcer.notNull (aFile, "File");

  return loadProperties (new FileSystemResource (aFile));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:8,代码来源:PropertiesHelper.java


示例17: _getChildResource

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Nonnull
private static FileSystemResource _getChildResource (@Nullable final File aBaseFile, @Nonnull final File aSystemFile)
{
  if (aBaseFile == null)
    return new FileSystemResource (aSystemFile);

  final File aParent = aBaseFile.isDirectory () ? aBaseFile : aBaseFile.getParentFile ();
  final File aRealFile = new File (aParent, aSystemFile.getPath ());
  // path is cleaned (canonicalized) inside FileSystemResource
  final FileSystemResource ret = new FileSystemResource (aRealFile);
  return ret;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:13,代码来源:DefaultResourceResolver.java


示例18: testGetAsFile

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Test
public void testGetAsFile ()
{
  final URL u = URLHelper.getAsURL ("file:/../dir/include.xml");
  final File f = URLHelper.getAsFile (u);
  assertNotNull (f);
  assertEquals (new File ("/../dir/include.xml").getAbsolutePath (), f.getAbsolutePath ());
  final FileSystemResource fs = new FileSystemResource (f);
  assertEquals (new File ("/dir/include.xml").getAbsolutePath (), fs.getPath ());
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:11,代码来源:URLHelperTest.java


示例19: readModifyAndWrite

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
public static boolean readModifyAndWrite (@Nonnull final File aSchematronFile) throws Exception
{
  final PSSchema aSchema = new PSReader (new FileSystemResource (aSchematronFile)).readSchema ();
  final PSTitle aTitle = new PSTitle ();
  aTitle.addText ("Created by ph-schematron");
  aSchema.setTitle (aTitle);
  return MicroWriter.writeToFile (aSchema.getAsMicroElement (), aSchematronFile).isSuccess ();
}
 
开发者ID:phax,项目名称:ph-schematron,代码行数:9,代码来源:DocumentationExamples.java


示例20: testInvalidSchematron

import com.helger.commons.io.resource.FileSystemResource; //导入依赖的package包/类
@Test
public void testInvalidSchematron ()
{
  assertFalse (new SchematronResourceSCH (new ClassPathResource ("test-sch/invalid01.sch")).isValidSchematron ());
  assertFalse (new SchematronResourceSCH (new ClassPathResource ("test-sch/this.file.does.not.exists")).isValidSchematron ());

  assertFalse (new SchematronResourceSCH (new FileSystemResource ("src/test/resources/test-sch/invalid01.sch")).isValidSchematron ());
  assertFalse (new SchematronResourceSCH (new FileSystemResource ("src/test/resources/test-sch/this.file.does.not.exists")).isValidSchematron ());
}
 
开发者ID:phax,项目名称:ph-schematron,代码行数:10,代码来源:SchematronResourceSCHCacheTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InclusiveNamespaces类代码示例发布时间:2022-05-23
下一篇:
Java AllocationException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap