本文整理匯總了Java中com.google.common.io.InputSupplier.getInput方法的典型用法代碼示例。如果您正苦於以下問題:Java InputSupplier.getInput方法的具體用法?Java InputSupplier.getInput怎麽用?Java InputSupplier.getInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.io.InputSupplier
的用法示例。
在下文中一共展示了InputSupplier.getInput方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getClassBody
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
private String getClassBody(Class<?> c) throws CompileException, IOException{
String path = c.getName();
path = path.replaceFirst("\\$.*", "");
path = path.replace(".", FileUtils.separator);
path = "/" + path + ".java";
URL u = Resources.getResource(c, path);
InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
try (InputStream is = supplier.getInput()) {
if (is == null) {
throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
}
String body = IO.toString(is);
//TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem...
//return body.replaceAll("@(?:Output|Param|Workspace|Override|SuppressWarnings\\([^\\\\]*?\\)|FunctionTemplate\\([^\\\\]*?\\))", "");
return body.replaceAll("@(?:\\([^\\\\]*?\\))?", "");
}
}
示例2: fromStream
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
/**
* Load the content of a file from a stream.
* <p>
* Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
* @param stream - the stream supplier.
* @param option - whether or not to decompress the input stream.
* @return The decoded NBT compound.
* @throws IOException If anything went wrong.
*/
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
InputStream input = null;
DataInputStream data = null;
boolean suppress = true;
try {
input = stream.getInput();
data = new DataInputStream(new BufferedInputStream(
option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input
));
NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
suppress = false;
return result;
} finally {
if (data != null)
Closeables.close(data, suppress);
else if (input != null)
Closeables.close(input, suppress);
}
}
示例3: fromStream
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
/**
* Load the content of a file from a stream.
* <p>
* Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
* @param stream - the stream supplier.
* @param option - whether or not to decompress the input stream.
* @return The decoded NBT compound.
* @throws IOException If anything went wrong.
*/
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
InputStream input = null;
DataInputStream data = null;
boolean suppress = true;
try {
input = stream.getInput();
data = new DataInputStream(new BufferedInputStream(
option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input
));
NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
suppress = false;
return result;
} finally {
if (data != null)
Closeables.close(data, suppress);
else if (input != null)
Closeables.close(input, suppress);
}
}
示例4: fromStream
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
/**
* Load the content of a file from a stream.
* <p>
* Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
*
* @param stream - the stream supplier.
* @param option - whether or not to decompress the input stream.
* @return The decoded NBT compound.
* @throws IOException If anything went wrong.
*/
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
InputStream input = null;
DataInputStream data = null;
boolean suppress = true;
try {
input = stream.getInput();
data = new DataInputStream(new BufferedInputStream(
option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input
));
NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
suppress = false;
return result;
} finally {
if (data != null)
Closeables.close(data, suppress);
else if (input != null)
Closeables.close(input, suppress);
}
}
示例5: LazyLoadFrame
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public LazyLoadFrame(Context context, InputSupplier<? extends InputStream> frame) throws IOException {
this.context = context;
DataInputStream din = new DataInputStream(frame.getInput());
int version = din.readInt();
if(version != VERSION) {
throw new IOException("Unsupported version: " + version);
}
int count = din.readInt();
for(int i=0;i!=count;++i) {
String name = din.readUTF();
int byteCount = din.readInt();
byte[] bytes = new byte[byteCount];
din.readFully(bytes);
map.put(Symbol.get(name), new Value(bytes));
}
din.close();
}
示例6: get
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
private CompilationUnit get(Class<?> c) throws IOException{
String path = c.getName();
path = path.replaceFirst("\\$.*", "");
path = path.replace(".", FileUtils.separator);
path = "/" + path + ".java";
CompilationUnit cu = functionUnits.get(path);
if(cu != null) {
return cu;
}
URL u = Resources.getResource(c, path);
InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);
try (InputStream is = supplier.getInput()) {
if (is == null) {
throw new IOException(String.format("Failure trying to located source code for Class %s, tried to read on classpath location %s", c.getName(), path));
}
String body = IO.toString(is);
//TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem...
body = body.replaceAll("@\\w+(?:\\([^\\\\]*?\\))?", "");
try{
cu = new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit();
functionUnits.put(path, cu);
return cu;
} catch (CompileException e) {
logger.warn("Failure while parsing function class:\n{}", body, e);
return null;
}
}
}
示例7: deserialize
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public static <T> T deserialize(final Persister persister, final InputSupplier<? extends InputStream> inputSupplier, final Class<T> clazz) throws IOException, ClassCastException, ClassNotFoundException {
final InputStream input = inputSupplier.getInput();
boolean threw = true;
try {
final T object = persister.deserialize(input, clazz);
threw = false;
return object;
} finally {
Closeables.close(input, threw);
}
}
示例8: toMap
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public static Multiset<String> toMap(InputSupplier<? extends InputStream> supplier) throws IOException {
InputStream input = supplier.getInput();
try {
Scanner scanner = new Scanner(input);
Multiset<String> m = HashMultiset.create();
while (scanner.hasNext()) {
String line = scanner.nextLine();
String[] parts = line.split("\t");
m.add(parts[0], Integer.parseInt(parts[1]));
}
return m;
} finally {
input.close();
}
}
示例9: decode
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public static JvmOptions decode(InputSupplier<? extends Reader> readerSupplier) throws IOException {
Reader reader = readerSupplier.getInput();
try {
return GSON.fromJson(reader, JvmOptions.class);
} finally {
reader.close();
}
}
示例10: decode
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public static Arguments decode(InputSupplier<? extends Reader> readerSupplier) throws IOException {
Reader reader = readerSupplier.getInput();
try {
return GSON.fromJson(reader, Arguments.class);
} finally {
reader.close();
}
}
示例11: parseSource
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public static ExpressionVector parseSource(
InputSupplier<InputStreamReader> source) throws IOException {
Reader reader = source.getInput();
try {
return parseAllSource(reader);
} finally {
Closeables.closeQuietly(reader);
}
// TODO Auto-generated method stub
}
示例12: parse
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public void parse(InputSupplier<InputStreamReader> readerSupplier) throws IOException {
Reader reader = readerSupplier.getInput();
try {
parse(reader);
} finally {
Closeables.closeQuietly(reader);
}
}
示例13: isRDataFile
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public static boolean isRDataFile(InputSupplier<InputStream> inputSupplier) throws IOException {
InputStream in = inputSupplier.getInput();
try {
byte streamType = readStreamType(in);
return streamType != -1;
} finally {
in.close();
}
}
示例14: decode
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
public static Arguments decode(InputSupplier<? extends Reader> readerSupplier) throws IOException {
try (Reader reader = readerSupplier.getInput()) {
return GSON.fromJson(reader, Arguments.class);
}
}
示例15: put
import com.google.common.io.InputSupplier; //導入方法依賴的package包/類
@Override
public void put(String tableName, String blobId, InputSupplier<? extends InputStream> in, Map<String,String> attributes, @Nullable Duration ttl) throws IOException {
checkLegalTableName(tableName);
checkLegalBlobId(blobId);
checkNotNull(in, "in");
checkNotNull(attributes, "attributes");
Table table = _tableDao.get(tableName);
long timestamp = _storageProvider.getCurrentTimestamp(table);
int chunkSize = _storageProvider.getDefaultChunkSize();
DigestInputStream md5In = new DigestInputStream(in.getInput(), getMessageDigest("MD5"));
DigestInputStream sha1In = new DigestInputStream(md5In, getMessageDigest("SHA-1"));
// A more aggressive solution like the Astyanax ObjectWriter recipe would improve performance by pipelining
// reading the input stream and writing chunks, and issuing the writes in parallel.
byte[] bytes = new byte[chunkSize];
long length = 0;
int chunkCount = 0;
for (;;) {
int chunkLength;
try {
chunkLength = ByteStreams.read(sha1In, bytes, 0, bytes.length);
} catch (IOException e) {
throw Throwables.propagate(e);
}
if (chunkLength == 0) {
break;
}
ByteBuffer buffer = ByteBuffer.wrap(bytes, 0, chunkLength);
_storageProvider.writeChunk(table, blobId, chunkCount, buffer, ttl, timestamp);
length += chunkLength;
chunkCount++;
}
// Include two types of hash: md5 (because it's common) and sha1 (because it's secure)
String md5 = Hex.encodeHexString(md5In.getMessageDigest().digest());
String sha1 = Hex.encodeHexString(sha1In.getMessageDigest().digest());
StorageSummary summary = new StorageSummary(length, chunkCount, chunkSize, md5, sha1, attributes, timestamp);
_storageProvider.writeMetadata(table, blobId, summary, ttl);
}