本文整理匯總了Java中org.apache.commons.io.FilenameUtils.getPrefix方法的典型用法代碼示例。如果您正苦於以下問題:Java FilenameUtils.getPrefix方法的具體用法?Java FilenameUtils.getPrefix怎麽用?Java FilenameUtils.getPrefix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.io.FilenameUtils
的用法示例。
在下文中一共展示了FilenameUtils.getPrefix方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parent
import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
private String parent(final String absolute) {
final String prefix = FilenameUtils.getPrefix(absolute);
if(absolute.equals(prefix)) {
return null;
}
int index = absolute.length() - 1;
if(absolute.charAt(index) == this.getDelimiter()) {
if(index > 0) {
index--;
}
}
final int cut = absolute.lastIndexOf(this.getDelimiter(), index);
if(cut > FilenameUtils.getPrefixLength(absolute)) {
return absolute.substring(0, cut);
}
return String.valueOf(prefix);
}
示例2: handle
import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
@Override
public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) {
if (context.getDebugSession() == null) {
return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Empty debug session.");
}
SetBreakpointArguments bpArguments = (SetBreakpointArguments) arguments;
String clientPath = bpArguments.source.path;
if (AdapterUtils.isWindows()) {
// VSCode may send drive letters with inconsistent casing which will mess up the key
// in the BreakpointManager. See https://github.com/Microsoft/vscode/issues/6268
// Normalize the drive letter casing. Note that drive letters
// are not localized so invariant is safe here.
String drivePrefix = FilenameUtils.getPrefix(clientPath);
if (drivePrefix != null && drivePrefix.length() >= 2
&& Character.isLowerCase(drivePrefix.charAt(0)) && drivePrefix.charAt(1) == ':') {
drivePrefix = drivePrefix.substring(0, 2); // d:\ is an illegal regex string, convert it to d:
clientPath = clientPath.replaceFirst(drivePrefix, drivePrefix.toUpperCase());
}
}
String sourcePath = clientPath;
if (bpArguments.source.sourceReference != 0 && context.getSourceUri(bpArguments.source.sourceReference) != null) {
sourcePath = context.getSourceUri(bpArguments.source.sourceReference);
} else if (StringUtils.isNotBlank(clientPath)) {
// See the bug https://github.com/Microsoft/vscode/issues/30996
// Source.path in the SetBreakpointArguments could be a file system path or uri.
sourcePath = AdapterUtils.convertPath(clientPath, AdapterUtils.isUri(clientPath), context.isDebuggerPathsAreUri());
}
// When breakpoint source path is null or an invalid file path, send an ErrorResponse back.
if (StringUtils.isBlank(sourcePath)) {
return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE,
String.format("Failed to setBreakpoint. Reason: '%s' is an invalid path.", bpArguments.source.path));
}
try {
List<Types.Breakpoint> res = new ArrayList<>();
IBreakpoint[] toAdds = this.convertClientBreakpointsToDebugger(sourcePath, bpArguments.breakpoints, context);
// See the VSCode bug https://github.com/Microsoft/vscode/issues/36471.
// The source uri sometimes is encoded by VSCode, the debugger will decode it to keep the uri consistent.
IBreakpoint[] added = manager.setBreakpoints(AdapterUtils.decodeURIComponent(sourcePath), toAdds, bpArguments.sourceModified);
for (int i = 0; i < bpArguments.breakpoints.length; i++) {
// For newly added breakpoint, should install it to debuggee first.
if (toAdds[i] == added[i] && added[i].className() != null) {
added[i].install().thenAccept(bp -> {
Events.BreakpointEvent bpEvent = new Events.BreakpointEvent("new", this.convertDebuggerBreakpointToClient(bp, context));
context.getProtocolServer().sendEvent(bpEvent);
});
} else if (toAdds[i].hitCount() != added[i].hitCount() && added[i].className() != null) {
// Update hitCount condition.
added[i].setHitCount(toAdds[i].hitCount());
}
res.add(this.convertDebuggerBreakpointToClient(added[i], context));
}
response.body = new Responses.SetBreakpointsResponseBody(res);
return CompletableFuture.completedFuture(response);
} catch (DebugException e) {
return AdapterUtils.createAsyncErrorResponse(response,
ErrorCode.SET_BREAKPOINT_FAILURE,
String.format("Failed to setBreakpoint. Reason: '%s'", e.toString()));
}
}