本文整理汇总了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()));
}
}