当前位置: 首页>>代码示例>>Java>>正文


Java InputSupplier类代码示例

本文整理汇总了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("@(?:\\([^\\\\]*?\\))?", "");
  }

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:20,代码来源:FunctionConverter.java

示例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;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:22,代码来源:ProjectBuilder.java

示例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);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:24,代码来源:CasBlobStoreTest.java

示例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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:JcloudsPayloadConverter.java

示例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);
    }
}
 
开发者ID:Mayomi,项目名称:PlotSquared-Chinese,代码行数:32,代码来源:NbtFactory.java

示例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();
    }
}
 
开发者ID:TheAwesomeGem,项目名称:MineFantasy,代码行数:26,代码来源:BattlegearTranslator.java

示例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"));
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:17,代码来源:ReadPropertiesFile.java

示例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;
}
 
开发者ID:desperado1992,项目名称:distributeTemplate,代码行数:34,代码来源:FileSystemService.java

示例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());
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:23,代码来源:JvmOptionsCodecTest.java

示例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());
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:22,代码来源:JvmOptionsCodecTest.java

示例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());
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:23,代码来源:JvmOptionsCodecTest.java

示例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);
    }
}
 
开发者ID:Kingdoms-of-Arden-Development,项目名称:Crafty,代码行数:32,代码来源:NbtFactory.java

示例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);
	}
}
 
开发者ID:KingFaris10,项目名称:KingKits,代码行数:33,代码来源:NbtFactory.java

示例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);
      }
   });
}
 
开发者ID:jclouds,项目名称:jclouds-examples,代码行数:17,代码来源:HdfsPayloadSlicer.java

示例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();
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:19,代码来源:LazyLoadFrame.java


注:本文中的com.google.common.io.InputSupplier类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。