Search in sources :

Example 16 with InvalidPathException

use of java.nio.file.InvalidPathException in project knime-core by knime.

the class CreateFilenameNodeModel method handleSlash.

/**
 * This method handles the slash between the base dir path and the file name.
 *
 * @param baseDir the directory path
 * @param name the file name
 * @param ext the file extension
 * @return the concatenated string of all three input, or -1 if exception occurred.
 */
protected static String handleSlash(String baseDir, final String name, final String ext) {
    String output = "";
    try {
        if (baseDir.endsWith("?")) {
            baseDir = Pattern.compile("[?]+$").matcher(baseDir).replaceAll("");
        }
        if (!(baseDir.endsWith("/") || baseDir.endsWith("\\"))) {
            if (!baseDir.toLowerCase().startsWith("knime") && IS_WINDOWS) {
                output = baseDir + "\\" + name + ext;
            } else {
                output = baseDir + "/" + name + ext;
            }
        } else {
            Matcher slash = Pattern.compile("[/]+$").matcher(baseDir);
            if (slash.find()) {
                baseDir = slash.replaceAll("") + "/";
            }
            slash = Pattern.compile("[\\\\]+$").matcher(baseDir);
            if (slash.find()) {
                baseDir = slash.replaceAll("") + "\\";
            }
            output = baseDir + name + ext;
        }
    } catch (InvalidPathException e) {
        return "-1";
    }
    return output;
}
Also used : Matcher(java.util.regex.Matcher) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) InvalidPathException(java.nio.file.InvalidPathException)

Example 17 with InvalidPathException

use of java.nio.file.InvalidPathException in project knime-core by knime.

the class CSVFilesHistoryPanel method fileLocationChanged.

private void fileLocationChanged() {
    String selFile = getSelectedFile();
    m_warnMsg.setText("");
    if ((selFile != null) && !selFile.isEmpty()) {
        try {
            URL newUrl = FileUtil.toURL(selFile);
            m_warnMsg.checkLocation(newUrl);
        } catch (InvalidPathException ex) {
            m_warnMsg.setText("Invalid file system path: " + ex.getMessage());
            m_warnMsg.setForeground(Color.RED);
        } catch (IOException ex) {
        // ignore it
        }
    }
}
Also used : IOException(java.io.IOException) URL(java.net.URL) InvalidPathException(java.nio.file.InvalidPathException)

Example 18 with InvalidPathException

use of java.nio.file.InvalidPathException in project litiengine by gurkenlabs.

the class Program method handleArgs.

private static void handleArgs(String[] args) {
    if (args.length == 0) {
        return;
    }
    for (int i = 0; i < args.length; i++) {
        if (args[i] == null || args[i].isEmpty()) {
            continue;
        }
        // handle file loading
        if (i == 0) {
            if (args[i] == null || args[i].isEmpty()) {
                continue;
            }
            try {
                Paths.get(args[i]);
            } catch (InvalidPathException e) {
                continue;
            }
            File f = new File(args[i]);
            EditorScreen.instance().load(f);
        }
    }
}
Also used : File(java.io.File) InvalidPathException(java.nio.file.InvalidPathException)

Example 19 with InvalidPathException

use of java.nio.file.InvalidPathException in project Universal-Pointer-Searcher by BullyWiiPlaza.

the class UniversalPointerSearcherGUI method restorePersistentSettings.

private void restorePersistentSettings() {
    val lastAddedFilePath = persistentSettingsManager.get(LAST_ADDED_FILE_PATH.toString());
    if (lastAddedFilePath != null) {
        try {
            this.lastAddedFilePath = Paths.get(lastAddedFilePath);
        } catch (InvalidPathException exception) {
            handleException(exception);
        }
    }
    val pointerSearchDepth = persistentSettingsManager.get(POINTER_SEARCH_DEPTH.toString());
    if (pointerSearchDepth != null) {
        pointerSearchDepthField.setText(pointerSearchDepth);
    }
    val pointerValueAlignment = persistentSettingsManager.get(POINTER_VALUE_ALIGNMENT.toString());
    if (pointerValueAlignment != null) {
        pointerValueAlignmentField.setText(pointerValueAlignment);
    }
    val maximumMemoryChunkSize = persistentSettingsManager.get(MAXIMUM_MEMORY_CHUNK_SIZE.toString());
    if (maximumMemoryChunkSize != null) {
        maximumMemoryChunkSizeField.setText(maximumMemoryChunkSize);
    }
    val maximumOffset = persistentSettingsManager.get(MAXIMUM_OFFSET.toString());
    if (maximumOffset != null) {
        maximumPointerOffsetField.setText(maximumOffset);
    }
    val allowNegativeOffsets = persistentSettingsManager.get(ALLOW_NEGATIVE_OFFSETS.toString());
    if (allowNegativeOffsets != null) {
        val selected = parseBoolean(allowNegativeOffsets);
        allowNegativeOffsetsCheckBox.setSelected(selected);
    }
    val singleMemoryDumpMethod = persistentSettingsManager.get(SINGLE_MEMORY_DUMP_METHOD.toString());
    if (singleMemoryDumpMethod != null) {
        val selected = parseBoolean(singleMemoryDumpMethod);
        singleMemoryDumpMethodCheckBox.setSelected(selected);
    }
    val baseOffsetRange = persistentSettingsManager.get(BASE_OFFSET_RANGE.toString());
    if (baseOffsetRange != null) {
        val selected = parseBoolean(baseOffsetRange);
        baseOffsetRangeSelection.setSelected(selected);
    }
    val startingBaseAddress = persistentSettingsManager.get(STARTING_BASE_ADDRESS.toString());
    if (startingBaseAddress != null) {
        startingBaseAddressField.setText(startingBaseAddress);
    }
    val endBaseAddress = persistentSettingsManager.get(END_BASE_ADDRESS.toString());
    if (endBaseAddress != null) {
        endBaseAddressField.setText(endBaseAddress);
    }
}
Also used : lombok.val(lombok.val) InvalidPathException(java.nio.file.InvalidPathException)

Example 20 with InvalidPathException

use of java.nio.file.InvalidPathException in project yii2support by nvlad.

the class ViewUtil method resolveViewFromController.

@NotNull
private static ViewResolve resolveViewFromController(PhpClass clazz, String value) {
    ViewResolve result = new ViewResolve(ViewResolveFrom.Controller);
    final String classFQN = clazz.getFQN().replace('\\', '/');
    StringBuilder key = new StringBuilder("@app");
    String path = deletePathPart(classFQN);
    if (path.startsWith("/modules/")) {
        key.append("/modules");
        path = deletePathPart(path);
    }
    int controllersPathPartPosition = path.indexOf("/controllers/");
    if (controllersPathPartPosition == -1) {
        throw new InvalidPathException(path, "Not found \"controllers\" directory.");
    }
    result.application = getFirstPathPart(classFQN);
    if (controllersPathPartPosition > 0) {
        final String module = path.substring(0, controllersPathPartPosition);
        key.append(module);
        path = path.substring(controllersPathPartPosition);
        result.module = module;
    }
    path = deletePathPart(path);
    key.append("/views");
    if (value.startsWith("/")) {
        result.key = normalizePath(key + value);
        return result;
    }
    final String className = clazz.getName();
    key.append(path, 0, path.length() - className.length());
    key.append(StringUtils.CamelToId(className.substring(0, className.length() - 10), "-"));
    key.append('/');
    key.append(value);
    result.key = normalizePath(key.toString());
    return result;
}
Also used : ViewResolve(com.nvlad.yii2support.views.entities.ViewResolve) InvalidPathException(java.nio.file.InvalidPathException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)97 Path (java.nio.file.Path)53 IOException (java.io.IOException)26 URL (java.net.URL)14 File (java.io.File)13 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 InputStream (java.io.InputStream)4 FileOutStream (alluxio.client.file.FileOutStream)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)2