當前位置: 首頁>>代碼示例>>Java>>正文


Java InvalidPathException類代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:Util.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:Stamps.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:JarClassLoader.java

示例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;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:ArchiveURLMapper.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:LocalFileSystem.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:BaseUtilities.java

示例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;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:TranslogTests.java

示例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;
	}
}
 
開發者ID:zeobviouslyfakeacc,項目名稱:ModLoaderInstaller,代碼行數:23,代碼來源:MainPanel.java

示例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);
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:19,代碼來源:XMLUtils.java

示例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);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:23,代碼來源:Local.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:ProxyClassesDumper.java

示例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
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:ProxyClassesDumper.java

示例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;
            }
        }
    }
 
開發者ID:MatteoJoliveau,項目名稱:PlugFace,代碼行數:24,代碼來源:DefaultPluginManager.java

示例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;
    }
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:23,代碼來源:PathValidator.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:ProxyClassesDumper.java


注:本文中的java.nio.file.InvalidPathException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。