This implementation creates a FileSystemResource, applying the given path
relative to the path of the underlying file of this resource descriptor.
508920
public Resource createRelative(String relativePath) {
        String pathToUse = GrailsResourceUtils.applyRelativePath(path, relativePath);
        return new FileSystemResource(pathToUse);
    }
560853
@Override
    public Resource createRelative(String relativePath) throws IOException {
        return new PathResource(this.path.resolve(relativePath));
    }
733716
private Resource newResource(final String relativePath, final File classpathResourceFile) {
        return new Resource(this, classpathResourceFile.length()) {
            /** The random access file. */
            private RandomAccessFile randomAccessFile;

            /** The file channel. */
            private FileChannel fileChannel;

            @Override
            public String getPath() {
                return relativePath;
            }

            @Override
            public String getPathRelativeToClasspathElement() {
                return relativePath;
            }

            @Override
            public synchronized ByteBuffer read() throws IOException {
                if (skipClasspathElement) {
                    // Shouldn't happen
                    throw new IOException("Parent directory could not be opened");
                }
                markAsOpen();
                try {
                    randomAccessFile = new RandomAccessFile(classpathResourceFile, "r");
                    fileChannel = randomAccessFile.getChannel();
                    MappedByteBuffer buffer = null;
                    try {
                        buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
                    } catch (final FileNotFoundException e) {
                        throw e;
                    } catch (IOException | OutOfMemoryError e) {
                        // If map failed, try calling System.gc() to free some allocated MappedByteBuffers
                        // (there is a limit to the number of mapped files -- 64k on Linux)
                        // See: http://www.mapdb.org/blog/mmap_files_alloc_and_jvm_crash/
                        System.gc();
                        // Then try calling map again
                        buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
                    }
                    byteBuffer = buffer;
                    length = byteBuffer.remaining();
                    return byteBuffer;
                } catch (final IOException | SecurityException | OutOfMemoryError e) {
                    close();
                    throw new IOException("Could not open " + this, e);
                }
            }

            @Override
            synchronized InputStreamOrByteBufferAdapter openOrRead() throws IOException {
                if (length >= FileUtils.FILECHANNEL_FILE_SIZE_THRESHOLD) {
                    return new InputStreamOrByteBufferAdapter(read());
                } else {
                    return new InputStreamOrByteBufferAdapter(inputStream = new InputStreamResourceCloser(this,
                            Files.newInputStream(classpathResourceFile.toPath())));
                }
            }

            @Override
            public synchronized InputStream open() throws IOException {
                if (length >= FileUtils.FILECHANNEL_FILE_SIZE_THRESHOLD) {
                    read();
                    return inputStream = new InputStreamResourceCloser(this, byteBufferToInputStream());
                } else {
                    markAsOpen();
                    try {
                        return inputStream = new InputStreamResourceCloser(this,
                                Files.newInputStream(classpathResourceFile.toPath()));
                    } catch (final IOException | SecurityException e) {
                        close();
                        throw new IOException("Could not open " + this, e);
                    }
                }
            }

            @Override
            public synchronized byte[] load() throws IOException {
                try {
                    final byte[] byteArray;
                    if (length >= FileUtils.FILECHANNEL_FILE_SIZE_THRESHOLD) {
                        read();
                        byteArray = byteBufferToByteArray();
                    } else {
                        open();
                        byteArray = FileUtils.readAllBytesAsArray(inputStream, length);
                    }
                    length = byteArray.length;
                    return byteArray;
                } finally {
                    close();
                }
            }

            @Override
            public synchronized void close() {
                super.close(); // Close inputStream
                if (byteBuffer != null) {
                    FileUtils.closeDirectByteBuffer(byteBuffer, /* log = */ null);
                    byteBuffer = null;
                }
                if (fileChannel != null) {
                    try {
                        fileChannel.close();
                    } catch (final IOException e) {
                        // Ignore
                    }
                    fileChannel = null;
                }
                if (randomAccessFile != null) {
                    try {
                        randomAccessFile.close();
                    } catch (final IOException e) {
                        // Ignore
                    }
                    randomAccessFile = null;
                }
                markAsClosed();
            }
        };
    }
169952
public Resource addPath(String path)
        throws IOException,MalformedURLException
    {
        FileResource r=null;

        if (!isDirectory())
        {
            r=(FileResource)super.addPath(path);
        }
        else
        {
            path = org.browsermob.proxy.jetty.util.URI.canonicalPath(path);
            
            // treat all paths being added as relative
            String rel=path;
            if (path.startsWith("/"))
                rel = path.substring(1);
            
            File newFile = new File(_file,rel.replace('/', File.separatorChar));
            r=new FileResource(newFile.toURI().toURL(),null,newFile);
        }
        
        String encoded= org.browsermob.proxy.jetty.util.URI.encodePath(path);
        int expected=r._urlString.length()-encoded.length();
        int index = r._urlString.lastIndexOf(encoded, expected);
        
        if (expected!=index && ((expected-1)!=index || path.endsWith("/") || !r.isDirectory()))
        {
            r._alias=r._url;
            r._aliasChecked=true;
        }                   
        return r;
    }
77643
@Override
    Resource getResource(final String relativePath) {
        return allResourcePaths.contains(relativePath) ? newResource(relativePath) : null;
    }
744968
public static void copyResourceFile(String source, Path target) throws IOException {
        InputStream resource = FsCrawlerUtil.class.getResourceAsStream(source);
        FileUtils.copyInputStreamToFile(resource, target.toFile());
    }
1313617
public static Path provisionResourceToFs(File localResource, FileSystem fs, String applicationName) throws Exception {
		String destinationFilePath = applicationName + "/" + localResource.getName();
		Path provisionedPath = new Path(fs.getHomeDirectory(), destinationFilePath);
		provisioinResourceToFs(fs, new Path(localResource.getAbsolutePath()), provisionedPath);
		return provisionedPath;
	}
729645
@Override
    public Resource createRelative(String relativePath) {
        String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
        return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
    }
471777
@Override
	public Resource createRelative(String relativePath) throws MalformedURLException {
		if (relativePath.startsWith("/")) {
			relativePath = relativePath.substring(1);
		}
		return new UrlResource(new URL(this.url, relativePath));
	}
86350
@Override
    Resource getResource(final String relativePath) {
        final File resourceFile = new File(classpathEltDir, relativePath);
        return resourceFile.canRead() && resourceFile.isFile() ? newResource(relativePath, resourceFile) : null;
    }
1070768
@Deprecated
    public static ResourceHandler.Builder fileHandler(Path path) {
        return new Builder().withResourceProviderFactory(ResourceProviderFactory.fileBased(path));
    }
52199
public boolean isDirectory(String path) {

		boolean isDirectory = false;
		String realPath = getRealResourcePath(path);
		if (isFileSystemPath(path, realPath)) { // The resource has been
												// remapped to a file system
												// path
			isDirectory = new File(realPath).isDirectory();
		} else {
			isDirectory = super.isDirectory(realPath);
		}
		return isDirectory;
	}
1293960
public static final Path create(Path path, Path target, String perms) throws IOException
    {
        FileAttribute<?>[] attrs = getFileAttributes(perms);
        switch (perms.charAt(0))
        {
            case '-':
                return Files.createFile(path, attrs);
            case 'l':
                if (target == null)
                {
                    throw new IllegalArgumentException("no target");
                }
                return Files.createSymbolicLink(path, target, attrs);
            case 'd':
                return Files.createDirectories(path, attrs);
            default:
                throw new IllegalArgumentException(perms+" illegal to this method");
        }
    }
497829
private File withPath(Path path, File dir) {
        return new File(dir, path.getPath());
    }
916893
static void createFileFromResource(String resource, Resource file) throws IOException {
	createFileFromResource(resource, file, null);
    }
172202
@Override
	public Set<InputStream> getResourcesAsStream(final String path) throws IOException
	{
		// For local paths, try to resolve the path relative to the folder of the master file
		// N.B. Assumes paths are sensible, not .//someFile.xml
		if (path.startsWith("./"))
		{
			final Set<InputStream> streams = inner.getResourcesAsStream(folder + path.substring(2));

			if (streams != null && !streams.isEmpty())
				return streams;
		}

		return inner.getResourcesAsStream(path);
	}
1045406
public static void createFileWithParentDirectories(Path path,
            FileAttribute<?>... attrs) {
        createDirectories(path.getParent(), attrs);
        createFile(path, attrs);
    }