本文整理汇总了Java中com.google.common.io.InputSupplier类的典型用法代码示例。如果您正苦于以下问题:Java InputSupplier类的具体用法?Java InputSupplier怎么用?Java InputSupplier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InputSupplier类属于com.google.common.io包,在下文中一共展示了InputSupplier类的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: extractProjectFiles
import com.google.common.io.InputSupplier; //导入依赖的package包/类
private ArrayList<String> extractProjectFiles(ZipFile inputZip, File projectRoot)
throws IOException {
ArrayList<String> projectFileNames = Lists.newArrayList();
Enumeration<? extends ZipEntry> inputZipEnumeration = inputZip.entries();
while (inputZipEnumeration.hasMoreElements()) {
ZipEntry zipEntry = inputZipEnumeration.nextElement();
final InputStream extractedInputStream = inputZip.getInputStream(zipEntry);
File extractedFile = new File(projectRoot, zipEntry.getName());
LOG.info("extracting " + extractedFile.getAbsolutePath() + " from input zip");
Files.createParentDirs(extractedFile); // Do I need this?
Files.copy(
new InputSupplier<InputStream>() {
public InputStream getInput() throws IOException {
return extractedInputStream;
}
},
extractedFile);
projectFileNames.add(extractedFile.getPath());
}
return projectFileNames;
}
示例3: verifyPutAndGet
import com.google.common.io.InputSupplier; //导入依赖的package包/类
private void verifyPutAndGet(String blobId, final byte[] blobData, Map<String, String> attributes, @Nullable Duration ttl)
throws IOException {
_store.put(TABLE, blobId, new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return new ByteArrayInputStream(blobData);
}
}, attributes, ttl);
// verify that we can get what we put
Blob blob = _store.get(TABLE, blobId);
assertEquals(blob.getId(), blobId);
assertEquals(blob.getLength(), blobData.length);
assertEquals(blob.getAttributes(), attributes);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
blob.writeTo(buf);
assertEquals(buf.toByteArray(), blobData);
BlobMetadata md = _store.getMetadata(TABLE, blobId);
assertEquals(md.getId(), blobId);
assertEquals(md.getLength(), blobData.length);
assertEquals(md.getAttributes(), attributes);
}
示例4: toPayload
import com.google.common.io.InputSupplier; //导入依赖的package包/类
@Converter
public static Payload toPayload(final InputStream is, Exchange exchange) throws IOException {
InputStreamPayload payload = new InputStreamPayload(is);
// only set the contentlength if possible
if (is.markSupported()) {
long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return is;
}
});
is.reset();
payload.getContentMetadata().setContentLength(contentLength);
}
return payload;
}
示例5: 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);
}
}
示例6: setup
import com.google.common.io.InputSupplier; //导入依赖的package包/类
public static void setup(String deobFileName){
try{
LZMAInputSupplier zis = new LZMAInputSupplier(FMLInjectionData.class.getResourceAsStream(deobFileName));
InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8);
List<String> srgList = CharStreams.readLines(srgSupplier);
for (String line : srgList) {
line = line.replace(" #C", "").replace(" #S", "");
if (line.startsWith("CL")) {
parseClass(line);
} else if (line.startsWith("FD")) {
parseField(line);
} else if (line.startsWith("MD")) {
parseMethod(line);
}
}
}catch(Exception e){
e.printStackTrace();
}
}
示例7: read_properties_file_guava
import com.google.common.io.InputSupplier; //导入依赖的package包/类
@Test
public void read_properties_file_guava() throws IOException {
URL url = Resources.getResource(PROPERTY_FILE_NAME);
InputSupplier<InputStream> inputSupplier =
Resources.newInputStreamSupplier(url);
Properties properties = new Properties();
properties.load(inputSupplier.getInput());
logger.info(properties);
assertEquals("http://www.leveluplunch.com", properties.getProperty("website"));
assertEquals("English", properties.getProperty("language"));
assertEquals("Welcome up to leveluplunch.com", properties.getProperty("message"));
}
示例8: wrapFile
import com.google.common.io.InputSupplier; //导入依赖的package包/类
/**
* 将文件打包成消息协议
* @param file
* @return
* 添加(修改)人:zhuyuping
* @throws Exception
* @throws FileNotFoundException
*/
private FileDataMessage wrapFile(File file){
FileDataMessage fm=new FileDataMessage();
try{
final InputStream input=new FileInputStream(file);
fm.setBytes(ByteStreams.toByteArray(input));
fm.setSessionId(System.identityHashCode(file.getAbsolutePath()));
fm.setHead(1314);
fm.setCommand(1);
fm.setLenth(file.length());
fm.setPath(file.getAbsolutePath());
fm.setStart(0);
fm.setEnd(file.length());
fm.setHash(ByteStreams.getChecksum(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return input;
}
}, new Adler32()));//crc32最强验证 adl32最弱验证
}catch(Exception e){
}
return fm;
}
示例9: testNoNulls
import com.google.common.io.InputSupplier; //导入依赖的package包/类
@Test
public void testNoNulls() throws Exception {
JvmOptions options = new JvmOptions("-version",
new JvmOptions.DebugOptions(true, false, ImmutableSet.of("one", "two")));
final StringWriter writer = new StringWriter();
JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
@Override
public Writer getOutput() throws IOException {
return writer;
}
});
JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
@Override
public Reader getInput() throws IOException {
return new StringReader(writer.toString());
}
});
Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
示例10: testSomeNulls
import com.google.common.io.InputSupplier; //导入依赖的package包/类
@Test
public void testSomeNulls() throws Exception {
JvmOptions options = new JvmOptions(null, new JvmOptions.DebugOptions(false, false, null));
final StringWriter writer = new StringWriter();
JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
@Override
public Writer getOutput() throws IOException {
return writer;
}
});
JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
@Override
public Reader getInput() throws IOException {
return new StringReader(writer.toString());
}
});
Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
示例11: testNoRunnables
import com.google.common.io.InputSupplier; //导入依赖的package包/类
@Test
public void testNoRunnables() throws Exception {
List<String> noRunnables = Collections.emptyList();
JvmOptions options = new JvmOptions(null, new JvmOptions.DebugOptions(true, false, noRunnables));
final StringWriter writer = new StringWriter();
JvmOptionsCodec.encode(options, new OutputSupplier<Writer>() {
@Override
public Writer getOutput() throws IOException {
return writer;
}
});
JvmOptions options1 = JvmOptionsCodec.decode(new InputSupplier<Reader>() {
@Override
public Reader getInput() throws IOException {
return new StringReader(writer.toString());
}
});
Assert.assertEquals(options.getExtraOptions(), options1.getExtraOptions());
Assert.assertEquals(options.getDebugOptions().doDebug(), options1.getDebugOptions().doDebug());
Assert.assertEquals(options.getDebugOptions().doSuspend(), options1.getDebugOptions().doSuspend());
Assert.assertEquals(options.getDebugOptions().getRunnables(), options1.getDebugOptions().getRunnables());
}
示例12: 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);
}
}
示例13: 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);
}
}
示例14: doSlice
import com.google.common.io.InputSupplier; //导入依赖的package包/类
protected Payload doSlice(final FSDataInputStream inputStream,
final long offset, final long length) {
return new InputStreamSupplierPayload(new InputSupplier<InputStream>() {
public InputStream getInput() throws IOException {
if (offset > 0) {
try {
inputStream.seek(offset);
} catch (IOException e) {
Closeables.closeQuietly(inputStream);
throw e;
}
}
return new LimitInputStream(inputStream, length);
}
});
}
示例15: 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();
}