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<>();
}
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");
}
}
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) {
}
}
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) {
}
}
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));
}
Aggregations