/** * Creates an instance of FSEntryResource to represent an entry based on the resource * specified by the classLoader and resource name. * @param classLoader Class loader used to find the resource * @param resourceName Actual name of resource * @return An entry representing the specified resource. * @throws Exception Invalid request */ static public FSEntryResource create(ClassLoader classLoader, String resourceName) throws Exception { return create(null, classLoader, resourceName); }
/** * Create a virtual tree hierarchy with a resource supporting the leaf. * @param path Position of the file in the hierarchy, including its name * @param classLoader Class loader used to find the needed resource * @param resourceName Name of the actual resource to obtain using class loader * @return The FSEntry root for this hierarchy * @throws Exception Invalid parameter */ static public FSEntry getPositionedResource(String path, ClassLoader classLoader, String resourceName) throws Exception { List<String> pathFrags = FSEntrySupport.interpretPath(path); // Start at leaf and work our way back int index = pathFrags.size() - 1; FSEntry root = create(pathFrags.get(index), classLoader, resourceName); --index; while(index >= 0){ FSEntryVirtualDirectory parent = new FSEntryVirtualDirectory(pathFrags.get(index)); parent.addChildEntry(root); root = parent; --index; } return root; }
FSEntryResource resourceFile = FSEntryResource.create(UserDesignDocument.class.getClassLoader(), "userDesignDocument"); Document doc = DocumentFile.createDocument(resourceFile, resourceFile);