下面列出了怎么用com.google.common.io.LimitInputStream的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* @return a mutable list
* @throws IOException
*/
private List<JSSourceFile> getDefaultExterns() throws IOException {
InputStream input = CommandLineRunner.class.getResourceAsStream(
"/externs.zip");
ZipInputStream zip = new ZipInputStream(input);
List<JSSourceFile> externs = Lists.newLinkedList();
for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null; ) {
LimitInputStream entryStream = new LimitInputStream(zip, entry.getSize());
externs.add(JSSourceFile.fromInputStream(entry.getName(), entryStream));
}
return externs;
}
/**
* @return a mutable list
* @throws IOException
*/
private List<JSSourceFile> getDefaultExterns() throws IOException {
InputStream input = CommandLineRunner.class.getResourceAsStream(
"/externs.zip");
ZipInputStream zip = new ZipInputStream(input);
List<JSSourceFile> externs = Lists.newLinkedList();
for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null; ) {
LimitInputStream entryStream = new LimitInputStream(zip, entry.getSize());
externs.add(JSSourceFile.fromInputStream(entry.getName(), entryStream));
}
return externs;
}
/**
* @return a mutable list
* @throws IOException
*/
public static List<JSSourceFile> getDefaultExterns() throws IOException {
InputStream input = CommandLineRunner.class.getResourceAsStream(
"/externs.zip");
ZipInputStream zip = new ZipInputStream(input);
Map<String, JSSourceFile> externsMap = Maps.newHashMap();
for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null; ) {
LimitInputStream entryStream = new LimitInputStream(zip, entry.getSize());
externsMap.put(entry.getName(),
JSSourceFile.fromInputStream(
// Give the files an odd prefix, so that they do not conflict
// with the user's files.
"externs.zip//" + entry.getName(),
entryStream));
}
Preconditions.checkState(
externsMap.keySet().equals(Sets.newHashSet(DEFAULT_EXTERNS_NAMES)),
"Externs zip must match our hard-coded list of externs.");
// Order matters, so the resources must be added to the result list
// in the expected order.
List<JSSourceFile> externs = Lists.newArrayList();
for (String key : DEFAULT_EXTERNS_NAMES) {
externs.add(externsMap.get(key));
}
return externs;
}
/**
* @return a mutable list
* @throws IOException
*/
public static List<JSSourceFile> getDefaultExterns() throws IOException {
InputStream input = CommandLineRunner.class.getResourceAsStream(
"/externs.zip");
ZipInputStream zip = new ZipInputStream(input);
Map<String, JSSourceFile> externsMap = Maps.newHashMap();
for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null; ) {
LimitInputStream entryStream = new LimitInputStream(zip, entry.getSize());
externsMap.put(entry.getName(),
JSSourceFile.fromInputStream(
// Give the files an odd prefix, so that they do not conflict
// with the user's files.
"externs.zip//" + entry.getName(),
entryStream));
}
Preconditions.checkState(
externsMap.keySet().equals(Sets.newHashSet(DEFAULT_EXTERNS_NAMES)),
"Externs zip must match our hard-coded list of externs.");
// Order matters, so the resources must be added to the result list
// in the expected order.
List<JSSourceFile> externs = Lists.newArrayList();
for (String key : DEFAULT_EXTERNS_NAMES) {
externs.add(externsMap.get(key));
}
return externs;
}
private List<JSSourceFile> getDefaultExterns() throws IOException {
InputStream input = ClosureJavaScriptCompressor.class.getResourceAsStream("/externs.zip");
ZipInputStream zip = new ZipInputStream(input);
List<JSSourceFile> externs = Lists.newLinkedList();
for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null;) {
LimitInputStream entryStream = new LimitInputStream(zip, entry.getSize());
externs.add(JSSourceFile.fromInputStream(entry.getName(), entryStream));
}
return externs;
}
/**
* @return a mutable list
* @throws IOException
*/
public static List<SourceFile> getDefaultExterns() throws IOException {
InputStream input = CommandLineRunner.class.getResourceAsStream(
"/externs.zip");
if (input == null) {
// In some environments, the externs.zip is relative to this class.
input = CommandLineRunner.class.getResourceAsStream("externs.zip");
}
Preconditions.checkNotNull(input);
ZipInputStream zip = new ZipInputStream(input);
Map<String, SourceFile> externsMap = Maps.newHashMap();
for (ZipEntry entry = null; (entry = zip.getNextEntry()) != null; ) {
BufferedInputStream entryStream = new BufferedInputStream(
new LimitInputStream(zip, entry.getSize()));
externsMap.put(entry.getName(),
SourceFile.fromInputStream(
// Give the files an odd prefix, so that they do not conflict
// with the user's files.
"externs.zip//" + entry.getName(),
entryStream));
}
Preconditions.checkState(
externsMap.keySet().equals(Sets.newHashSet(DEFAULT_EXTERNS_NAMES)),
"Externs zip must match our hard-coded list of externs.");
// Order matters, so the resources must be added to the result list
// in the expected order.
List<SourceFile> externs = Lists.newArrayList();
for (String key : DEFAULT_EXTERNS_NAMES) {
externs.add(externsMap.get(key));
}
return externs;
}