Search in sources :

Example 76 with InvalidPathException

use of java.nio.file.InvalidPathException in project ignite by apache.

the class GridLogCommandHandler method handleAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest req) {
    assert req != null;
    if (req.command() == LOG) {
        if (log.isDebugEnabled())
            log.debug("Handling log REST request: " + req);
        GridRestLogRequest req0 = (GridRestLogRequest) req;
        if (req0.from() < -1 || req0.to() < -1)
            return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "One of the request parameters is invalid [from=" + req0.from() + ", to=" + req0.to() + ']'));
        int from;
        if (req0.from() != -1) {
            if (req0.to() == -1)
                return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'to' is not set."));
            from = req0.from();
        } else
            from = DEFAULT_FROM;
        int to;
        if (req0.to() != -1) {
            if (req0.from() == -1)
                return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'from' is not set."));
            to = req0.to();
        } else
            to = DEFAULT_TO;
        if (from >= to)
            return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'from' must be less than 'to'."));
        File logFile;
        try {
            if (req0.path() != null) {
                if (log.fileName() != null) {
                    if (!req0.path().equals(log.fileName())) {
                        return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'path' must contain a path to valid log file."));
                    } else
                        logFile = new File(req0.path());
                } else if (req0.path().startsWith(ctx.config().getIgniteHome()))
                    logFile = new File(req0.path());
                else {
                    return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'path' must contain a path to valid log file."));
                }
            } else if (log.fileName() == null)
                logFile = new File(ctx.config().getIgniteHome() + "/work/log/ignite.log");
            else
                logFile = new File(log.fileName());
        } catch (InvalidPathException e) {
            return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Incorrect path to a log file [msg=" + e.getMessage() + ']'));
        }
        try {
            String content = readLog(from, to, logFile);
            return new GridFinishedFuture<>(new GridRestResponse(content));
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage()));
        }
    }
    return new GridFinishedFuture<>();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridRestLogRequest(org.apache.ignite.internal.processors.rest.request.GridRestLogRequest) File(java.io.File) InvalidPathException(java.nio.file.InvalidPathException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 77 with InvalidPathException

use of java.nio.file.InvalidPathException in project jimfs by google.

the class WindowsPathType method parseUncRoot.

/**
 * Parse the root of a UNC-style path, throwing an exception if the path does not start with a
 * valid UNC root.
 */
private String parseUncRoot(String path, String original) {
    Matcher uncMatcher = UNC_ROOT.matcher(path);
    if (uncMatcher.find()) {
        String host = uncMatcher.group(2);
        if (host == null) {
            throw new InvalidPathException(original, "UNC path is missing hostname");
        }
        String share = uncMatcher.group(3);
        if (share == null) {
            throw new InvalidPathException(original, "UNC path is missing sharename");
        }
        return path.substring(uncMatcher.start(), uncMatcher.end());
    } else {
        // probably shouldn't ever reach this
        throw new InvalidPathException(original, "Invalid UNC path");
    }
}
Also used : Matcher(java.util.regex.Matcher) InvalidPathException(java.nio.file.InvalidPathException)

Example 78 with InvalidPathException

use of java.nio.file.InvalidPathException in project j2objc by google.

the class InvalidPathExceptionTest method test_Constructor$String$String$Int.

public void test_Constructor$String$String$Int() {
    String reason = "reason";
    String input = "input";
    int index = 0;
    InvalidPathException exception = new InvalidPathException(input, reason, index);
    assertEquals(index, exception.getIndex());
    assertEquals(reason, exception.getReason());
    assertEquals(input, exception.getInput());
    // Test the case where index = -1.
    index = -1;
    exception = new InvalidPathException(input, reason, index);
    assertEquals(index, exception.getIndex());
    assertEquals(reason, exception.getReason());
    assertEquals(input, exception.getInput());
    // Test the case where index < -1;
    index = -2;
    try {
        new InvalidPathException(input, reason, index);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    // Test the case where input is null, reason is not null and index >= -1.
    try {
        index = 0;
        new InvalidPathException(null, reason, index);
        fail();
    } catch (NullPointerException expected) {
    }
    // Test the case where input is null, reason is not null and index < -1.
    try {
        index = -1;
        new InvalidPathException(null, reason, index);
        fail();
    } catch (NullPointerException expected) {
    }
    // Test the case where reason is null, input is not null and index >= -1.
    try {
        index = 0;
        new InvalidPathException(input, null, index);
        fail();
    } catch (NullPointerException expected) {
    }
    // Test the case where input is not null, reason is null and index < -1.
    try {
        index = -1;
        new InvalidPathException(input, null, index);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : InvalidPathException(java.nio.file.InvalidPathException)

Example 79 with InvalidPathException

use of java.nio.file.InvalidPathException in project j2objc by google.

the class InvalidPathExceptionTest method test_Constructor$String$String.

public void test_Constructor$String$String() {
    String reason = "reason";
    String input = "input";
    InvalidPathException exception = new InvalidPathException(input, reason);
    assertEquals(-1, exception.getIndex());
    assertEquals(reason, exception.getReason());
    assertEquals(input, exception.getInput());
    // Test the case where input is null and reason is not null.
    try {
        new InvalidPathException(null, reason);
        fail();
    } catch (NullPointerException expected) {
    }
    // Test the case where reason is null and input is not null.
    try {
        new InvalidPathException(input, null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : InvalidPathException(java.nio.file.InvalidPathException)

Example 80 with InvalidPathException

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

the class FilesHistoryPanel method fileLocationChanged.

private void fileLocationChanged() {
    String selFile = getSelectedFileWithPropertiesReplaced();
    m_warnMsg.setText("");
    if (StringUtils.isNotEmpty(selFile)) {
        try {
            URL url = FileUtil.toURL(selFile);
            m_warnMsg.checkLocation(url);
        } catch (InvalidPathException ex) {
            m_warnMsg.setText("Invalid file system path: " + ex.getMessage());
            m_warnMsg.setForeground(Color.RED);
        } catch (IOException ex) {
        // ignore
        }
    }
    final ChangeEvent changeEvent = new ChangeEvent(this);
    m_changeListener.stream().forEach(c -> c.stateChanged(changeEvent));
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) IOException(java.io.IOException) URL(java.net.URL) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)111 Path (java.nio.file.Path)58 IOException (java.io.IOException)30 File (java.io.File)17 URL (java.net.URL)15 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 ArrayList (java.util.ArrayList)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 BufferedReader (java.io.BufferedReader)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4