本文整理汇总了Java中java.nio.file.InvalidPathException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidPathException类的具体用法?Java InvalidPathException怎么用?Java InvalidPathException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidPathException类属于java.nio.file包,在下文中一共展示了InvalidPathException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeTempJar
import java.nio.file.InvalidPathException; //导入依赖的package包/类
/**
* Make a temporary copy of a JAR file.
*/
static File makeTempJar(File moduleFile) throws IOException {
String prefix = moduleFile.getName();
if (prefix.endsWith(".jar") || prefix.endsWith(".JAR")) { // NOI18N
prefix = prefix.substring(0, prefix.length() - 4);
}
if (prefix.length() < 3) prefix += '.';
if (prefix.length() < 3) prefix += '.';
if (prefix.length() < 3) prefix += '.';
String suffix = "-test.jar"; // NOI18N
File physicalModuleFile = File.createTempFile(prefix, suffix);
physicalModuleFile.deleteOnExit();
try (InputStream is = Files.newInputStream(moduleFile.toPath());
OutputStream os = Files.newOutputStream(physicalModuleFile.toPath())) {
byte[] buf = new byte[4096];
int i;
while ((i = is.read(buf)) != -1) {
os.write(buf, 0, i);
}
} catch (InvalidPathException ex) {
throw new IOException(ex);
}
err.fine("Made " + physicalModuleFile);
return physicalModuleFile;
}
示例2: clustersChanged
import java.nio.file.InvalidPathException; //导入依赖的package包/类
private static boolean clustersChanged() {
if (clustersChanged != null) {
return clustersChanged;
}
final String clustersCache = "all-clusters.dat"; // NOI18N
File f = fileImpl(clustersCache, null, -1); // no timestamp check
if (f != null) {
try (DataInputStream dis = new DataInputStream(Files.newInputStream(f.toPath()))) {
if (Clusters.compareDirs(dis)) {
return false;
}
} catch (IOException | InvalidPathException ex) {
return clustersChanged = true;
}
} else {
// missing cluster file signals caches are OK, for
// backward compatibility
return clustersChanged = false;
}
return clustersChanged = true;
}
示例3: readClass
import java.nio.file.InvalidPathException; //导入依赖的package包/类
protected byte[] readClass(String path) throws IOException {
File clsFile = new File(dir, path.replace('/', File.separatorChar));
if (!clsFile.exists()) return null;
int len = (int)clsFile.length();
byte[] data = new byte[len];
try (InputStream is = Files.newInputStream(clsFile.toPath())) {
int count = 0;
while (count < len) {
count += is.read(data, count, len - count);
}
return data;
} catch (InvalidPathException ex) {
throw new IOException(ex);
}
}
示例4: copyJAR
import java.nio.file.InvalidPathException; //导入依赖的package包/类
private static File copyJAR(FileObject fo, URI archiveFileURI, boolean replace) throws IOException {
synchronized (copiedJARs) {
File copy = copiedJARs.get(archiveFileURI);
if (copy == null || replace) {
if (copy == null) {
copy = File.createTempFile("copy", "-" + archiveFileURI.toString().replaceFirst(".+/", "")); // NOI18N
copy = copy.getCanonicalFile();
copy.deleteOnExit();
}
try (InputStream is = fo.getInputStream(); OutputStream os = Files.newOutputStream(copy.toPath())) {
FileUtil.copy(is, os);
} catch (InvalidPathException ex) {
throw new IOException(ex);
}
copiedJARs.put(archiveFileURI, copy);
}
return copy;
}
}
示例5: outputStream
import java.nio.file.InvalidPathException; //导入依赖的package包/类
protected OutputStream outputStream(final String name) throws java.io.IOException {
File f = getFile(name);
if (!f.exists()) {
f.getParentFile().mkdirs();
}
try {
OutputStream retVal = new BufferedOutputStream(Files.newOutputStream(f.toPath()));
// workaround for #42624
if (BaseUtilities.isMac()) {
retVal = getOutputStreamForMac42624(retVal, name);
}
return retVal;
} catch (InvalidPathException ex) {
throw new IOException(ex);
}
}
示例6: pathToURISupported
import java.nio.file.InvalidPathException; //导入依赖的package包/类
private static boolean pathToURISupported() {
Boolean res = pathURIConsistent;
if (res == null) {
boolean c;
try {
final File f = new File("küñ"); //NOI18N
c = f.toPath().toUri().equals(f.toURI());
} catch (InvalidPathException e) {
c = false;
}
if (!c) {
LOG.fine("The java.nio.file.Path.toUri is inconsistent with java.io.File.toURI"); //NOI18N
}
res = pathURIConsistent = c;
}
return res;
}
示例7: randomNonTranslogPatternString
import java.nio.file.InvalidPathException; //导入依赖的package包/类
private String randomNonTranslogPatternString(int min, int max) {
String string;
boolean validPathString;
do {
validPathString = false;
string = randomRealisticUnicodeOfCodepointLength(randomIntBetween(min, max));
try {
final Path resolved = translogDir.resolve(string);
// some strings (like '/' , '..') do not refer to a file, which we this method should return
validPathString = resolved.getFileName() != null;
} catch (InvalidPathException ex) {
// some FS don't like our random file names -- let's just skip these random choices
}
} while (Translog.PARSE_STRICT_ID_PATTERN.matcher(string).matches() || validPathString == false);
return string;
}
示例8: createPathFromText
import java.nio.file.InvalidPathException; //导入依赖的package包/类
private static Path createPathFromText(String text) {
if (text == null || text.isEmpty()) return null;
if (text.startsWith("\"") && text.endsWith("\"")) text = text.substring(1, text.length() - 1);
if (!text.endsWith(DLL_NAME)) return null;
try {
Path path = Paths.get(text);
if (!Files.isRegularFile(path)) {
error("Read error", "The DLL file you selected cannot be found.");
return null;
} else if (!Files.isReadable(path) || !Files.isWritable(path)) {
error("Read error", "The DLL file you selected cannot be read from or written to.\n\n" +
"Make sure that the file is not marked read-only and\n" +
"that you have the required permissions to write to it.");
return null;
}
return path;
} catch (InvalidPathException ipe) {
return null;
}
}
示例9: parseRelativePath
import java.nio.file.InvalidPathException; //导入依赖的package包/类
public static Path parseRelativePath(Node node, Path def) throws InvalidXMLException {
if(node == null) return def;
final String text = node.getValueNormalize();
try {
Path path = Paths.get(text);
if(path.isAbsolute()) {
throw new InvalidPathException(text, "Path is not relative");
}
for(Path part : path) {
if(part.toString().trim().startsWith("..")) {
throw new InvalidPathException(text, "Path contains an invalid component");
}
}
return path;
} catch(InvalidPathException e) {
throw new InvalidXMLException("Invalid relative path '" + text + "'", node, e);
}
}
示例10: Local
import java.nio.file.InvalidPathException; //导入依赖的package包/类
/**
* @param name Absolute path
*/
public Local(final String name) throws LocalAccessDeniedException {
String path = name;
if(PreferencesFactory.get().getBoolean("local.normalize.unicode")) {
path = new NFCNormalizer().normalize(path).toString();
}
if(PreferencesFactory.get().getBoolean("local.normalize.tilde")) {
path = new TildeExpander().expand(path);
}
if(PreferencesFactory.get().getBoolean("local.normalize.prefix")) {
path = new WorkdirPrefixer().normalize(path);
}
try {
this.path = Paths.get(path).toString();
}
catch(InvalidPathException e) {
throw new LocalAccessDeniedException(String.format("The name %s is not a valid path for the filesystem", path), e);
}
this.attributes = new LocalAttributes(path);
}
示例11: getInstance
import java.nio.file.InvalidPathException; //导入依赖的package包/类
public static ProxyClassesDumper getInstance(String path) {
if (null == path) {
return null;
}
try {
path = path.trim();
final Path dir = Paths.get(path.length() == 0 ? "." : path);
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
validateDumpDir(dir);
return null;
}
}, null, new FilePermission("<<ALL FILES>>", "read, write"));
return new ProxyClassesDumper(dir);
} catch (InvalidPathException ex) {
PlatformLogger.getLogger(ProxyClassesDumper.class.getName())
.warning("Path " + path + " is not valid - dumping disabled", ex);
} catch (IllegalArgumentException iae) {
PlatformLogger.getLogger(ProxyClassesDumper.class.getName())
.warning(iae.getMessage() + " - dumping disabled");
}
return null;
}
示例12: dumpClass
import java.nio.file.InvalidPathException; //导入依赖的package包/类
public void dumpClass(String className, final byte[] classBytes) {
Path file;
try {
file = dumpDir.resolve(encodeForFilename(className) + ".class");
} catch (InvalidPathException ex) {
PlatformLogger.getLogger(ProxyClassesDumper.class.getName())
.warning("Invalid path for class " + className);
return;
}
try {
Path dir = file.getParent();
Files.createDirectories(dir);
Files.write(file, classBytes);
} catch (Exception ignore) {
PlatformLogger.getLogger(ProxyClassesDumper.class.getName())
.warning("Exception writing to path at " + file.toString());
// simply don't care if this operation failed
}
}
示例13: loadPlugins
import java.nio.file.InvalidPathException; //导入依赖的package包/类
@Override
public final List<Plugin> loadPlugins(String pluginFolder, boolean autoregister) {
File folder = new File(pluginFolder);
LOGGER.debug("Loading from supplied plugin folder");
if (!folder.isDirectory()) {
throw new InvalidPathException(pluginFolder, "Set a valid plugin directory");
} else {
List<Plugin> loaded;
// if (isDebug()) {
// loaded = loadDebug(folder);
// } else {
loaded = load(folder);
// }
if (autoregister) {
for (Plugin p : loaded) {
getContext().addPlugin(p);
}
return loaded;
} else {
return loaded;
}
}
}
示例14: isValid
import java.nio.file.InvalidPathException; //导入依赖的package包/类
@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {
try {
if (StringUtils.isEmpty(value)) {
return true; // do not validate empty value there are other constraints for that e.g. @NotNull, @Size etc...
}
final Path path = Paths.get(value);
if (checkIfExists && !path.toFile().exists()) {
return false;
}
final String fileExt = FilenameUtils.getExtension(value);
return allowableFileExtensions.isEmpty() ||
!allowableFileExtensions.stream().filter(fileExt::equalsIgnoreCase).findFirst().orElse(StringUtils.EMPTY).isEmpty();
} catch (final InvalidPathException e) {
LOGGER.error(e.getMessage(), e);
return false;
}
}
示例15: getInstance
import java.nio.file.InvalidPathException; //导入依赖的package包/类
public static ProxyClassesDumper getInstance(String path) {
if (null == path) {
return null;
}
try {
path = path.trim();
final Path dir = Paths.get(path.length() == 0 ? "." : path);
AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Void run() {
validateDumpDir(dir);
return null;
}
}, null, new FilePermission("<<ALL FILES>>", "read, write"));
return new ProxyClassesDumper(dir);
} catch (InvalidPathException ex) {
PlatformLogger.getLogger(ProxyClassesDumper.class.getName())
.warning("Path " + path + " is not valid - dumping disabled", ex);
} catch (IllegalArgumentException iae) {
PlatformLogger.getLogger(ProxyClassesDumper.class.getName())
.warning(iae.getMessage() + " - dumping disabled");
}
return null;
}