本文整理了Java中com.squareup.wire.schema.Location.get()
方法的一些代码示例,展示了Location.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Location.get()
方法的具体详情如下:
包路径:com.squareup.wire.schema.Location
类名称:Location
方法名:get
暂无
代码示例来源:origin: square/wire
public static Location get(String path) {
return get("", path);
}
代码示例来源:origin: square/wire
/**
* Returns Google's protobuf descriptor, which defines standard options like default, deprecated,
* and java_package. If the user has provided their own version of the descriptor proto, that is
* preferred.
*/
private ProtoFile loadDescriptorProto() throws IOException {
InputStream resourceAsStream = SchemaLoader.class.getResourceAsStream("/" + DESCRIPTOR_PROTO);
try (BufferedSource buffer = Okio.buffer(Okio.source(resourceAsStream))) {
String data = buffer.readUtf8();
Location location = Location.get("", DESCRIPTOR_PROTO);
ProtoFileElement element = ProtoParser.parse(location, data);
return ProtoFile.get(element);
}
}
代码示例来源:origin: square/wire
/**
* Parses the {@code .wire} file at {@code base/path} and returns it. Returns null if no such
* file exists.
*/
private ProfileFileElement loadProfileFile(Path base, String path) throws IOException {
Source source = source(base, path);
if (source == null) return null;
try {
Location location = Location.get(base.toString(), path);
String data = Okio.buffer(source).readUtf8();
return new ProfileParser(location, data).read();
} catch (IOException e) {
throw new IOException("Failed to load " + source + " from " + base, e);
} finally {
source.close();
}
}
代码示例来源:origin: square/wire
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
if (file.getFileName().toString().endsWith(".proto")) {
total.incrementAndGet();
String data = new String(Files.readAllBytes(file), UTF_8);
Location location = Location.get(ROOT.toString(), file.toString());
try {
ProtoParser.parse(location, data);
} catch (Exception e) {
e.printStackTrace();
failed.incrementAndGet();
}
}
return FileVisitResult.CONTINUE;
}
});
代码示例来源:origin: square/wire
Location location = Location.get(base.toString(), proto);
String data = Okio.buffer(source).readUtf8();
element = ProtoParser.parse(location, data);
代码示例来源:origin: square/wire
@Test public void pathsToAttemptMultipleRoots() throws Exception {
FileSystem fileSystem = FileSystems.getDefault();
ImmutableSet<Location> locations = ImmutableSet.of(
Location.get("/a/b", "c/d/e.proto"),
Location.get("/a/b", "c/f/g/h.proto"),
Location.get("/i/j.zip", "k/l/m.proto"),
Location.get("/i/j.zip", "k/l/m/n.proto"));
ProfileLoader loader = new ProfileLoader(fileSystem, "android");
assertThat(loader.pathsToAttempt(locations).asMap()).containsExactly(
MapEntry.entry(fileSystem.getPath("/a/b"), ImmutableSet.of(
"c/d/android.wire",
"c/android.wire",
"android.wire",
"c/f/g/android.wire",
"c/f/android.wire")),
MapEntry.entry(fileSystem.getPath("/i/j.zip"), ImmutableSet.of(
"k/l/android.wire",
"k/android.wire",
"android.wire",
"k/l/m/android.wire")));
}
代码示例来源:origin: square/wire
@Test public void pathsToAttempt() throws Exception {
FileSystem fileSystem = FileSystems.getDefault();
ImmutableSet<Location> locations = ImmutableSet.of(
Location.get("/a/b", "c/d/e.proto"));
ProfileLoader loader = new ProfileLoader(fileSystem, "android");
assertThat(loader.pathsToAttempt(locations).asMap()).containsExactly(
MapEntry.entry(fileSystem.getPath("/a/b"), ImmutableSet.of(
"c/d/android.wire",
"c/android.wire",
"android.wire")));
}
代码示例来源:origin: square/wire
public static void main(String... args) {
int total = 0;
int failed = 0;
Deque<File> fileQueue = new ArrayDeque<>();
fileQueue.add(ROOT);
while (!fileQueue.isEmpty()) {
File file = fileQueue.removeFirst();
if (file.isDirectory()) {
Collections.addAll(fileQueue, file.listFiles());
} else if (file.getName().endsWith(".proto")) {
System.out.println("Parsing " + file.getPath());
total += 1;
try (BufferedSource in = Okio.buffer(Okio.source(file))) {
String data = in.readUtf8();
ProtoParser.parse(Location.get(file.getPath()), data);
} catch (Exception e) {
e.printStackTrace();
failed += 1;
}
}
}
System.out.println("\nTotal: " + total + " Failed: " + failed);
}
}
代码示例来源:origin: sixt/ja-micro
public List<RpcMethodDefinition> getRpcMethods() throws IOException {
List<RpcMethodDefinition> retval = new ArrayList<>();
ProtoParser parser = new ProtoParser(Location.get(input.getCanonicalPath()), gulpFile(input));
ProtoFileElement element = parser.readProtoFile();
if (protoFileMatchesPackage(element)) {
List<ServiceElement> services = element.services();
if (services != null) {
for (ServiceElement service : services) {
String name = service.name();
List<RpcElement> rpcs = service.rpcs();
if (rpcs != null) {
for (RpcElement rpc : rpcs) {
RpcMethodDefinition def = new RpcMethodDefinition(name + "." + rpc.name(),
rpc.requestType(), rpc.responseType(),
element.packageName(), fileName
);
retval.add(def);
}
}
}
}
}
return retval;
}
代码示例来源:origin: ppdai-incubator/raptor
public static Location get(String path) {
return get("", path);
}
代码示例来源:origin: com.squareup.wire/wire-schema
public static Location get(String path) {
return get("", path);
}
代码示例来源:origin: com.squareup.wire/wire-schema
/**
* Returns Google's protobuf descriptor, which defines standard options like default, deprecated,
* and java_package. If the user has provided their own version of the descriptor proto, that is
* preferred.
*/
private ProtoFile loadDescriptorProto() throws IOException {
InputStream resourceAsStream = SchemaLoader.class.getResourceAsStream("/" + DESCRIPTOR_PROTO);
try (BufferedSource buffer = Okio.buffer(Okio.source(resourceAsStream))) {
String data = buffer.readUtf8();
Location location = Location.get("", DESCRIPTOR_PROTO);
ProtoFileElement element = ProtoParser.parse(location, data);
return ProtoFile.get(element);
}
}
代码示例来源:origin: ppdai-incubator/raptor
/**
* Returns Google's protobuf descriptor, which defines standard options like default, deprecated,
* and java_package. If the user has provided their own version of the descriptor proto, that is
* preferred.
*/
private ProtoFile loadDescriptorProto() throws IOException {
InputStream resourceAsStream = SchemaLoader.class.getResourceAsStream("/" + DESCRIPTOR_PROTO);
try (BufferedSource buffer = Okio.buffer(Okio.source(resourceAsStream))) {
String data = buffer.readUtf8();
Location location = Location.get("", DESCRIPTOR_PROTO);
ProtoFileElement element = ProtoParser.parse(location, data);
return ProtoFile.get(element);
}
}
代码示例来源:origin: ppdai-incubator/raptor
/**
* Parses the {@code .wire} file at {@code base/path} and returns it. Returns null if no such
* file exists.
*/
private AbstractProfileFileElement loadProfileFile(Path base, String path) throws IOException {
Source source = source(base, path);
if (source == null) {
return null;
}
try {
Location location = Location.get(base.toString(), path);
String data = Okio.buffer(source).readUtf8();
return new ProfileParser(location, data).read();
} catch (IOException e) {
throw new IOException("Failed to load " + source + " from " + base, e);
} finally {
source.close();
}
}
代码示例来源:origin: com.squareup.wire/wire-schema
Location location = Location.get(base.toString(), proto);
String data = Okio.buffer(source).readUtf8();
element = ProtoParser.parse(location, data);
代码示例来源:origin: ppdai-incubator/raptor
Location location = Location.get(base.toString(), proto);
String data = Okio.buffer(source).readUtf8();
element = ProtoParser.parse(location, data);
内容来源于网络,如有侵权,请联系作者删除!