All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.vfs.VirtualFile Maven / Gradle / Ivy

There is a newer version: 2.6.2
Show newest version
package play.vfs;

import static org.apache.commons.io.FileUtils.readFileToByteArray;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import play.exceptions.UnexpectedException;

/**
 * @deprecated This class is not needed anymore. It was used in Play! framework to load resources
 *     from local folder "modules" which was a custom dependency management mechanism. RePlay uses
 *     standard Maven/Gradle dependencies. Folder "modules" doesn't exist anymore.
 *     

So we use plain old {@link java.io.File} instead. */ @Deprecated public class VirtualFile { private final File realFile; private VirtualFile(File file) { this.realFile = file; } public String getName() { return realFile.getName(); } public boolean exists() { return realFile != null && realFile.exists(); } public long length() { return realFile.length(); } @Nonnull @CheckReturnValue public VirtualFile child(String name) { return new VirtualFile(new File(realFile, name)); } public static VirtualFile open(String file) { return open(new File(file)); } public static VirtualFile open(File file) { return new VirtualFile(file); } public File getRealFile() { return realFile; } public URI getURI() { return getRealFile().toURI(); } public byte[] content() { try { return readFileToByteArray(realFile); } catch (IOException e) { throw new UnexpectedException("Failed to read " + realFile.getAbsolutePath(), e); } } @Override public String toString() { return getName(); } @Deprecated @Nullable public static VirtualFile search(Collection roots, String path) { for (VirtualFile file : roots) { if (file.child(path).exists()) { return file.child(path); } } return null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy