當前位置: 首頁>>代碼示例>>Java>>正文


Java InputSupplier.getInput方法代碼示例

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

}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:20,代碼來源:FunctionConverter.java

示例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);
    }
}
 
開發者ID:Mayomi,項目名稱:PlotSquared-Chinese,代碼行數:32,代碼來源:NbtFactory.java

示例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);
    }
}
 
開發者ID:Kingdoms-of-Arden-Development,項目名稱:Crafty,代碼行數:32,代碼來源:NbtFactory.java

示例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);
	}
}
 
開發者ID:KingFaris10,項目名稱:KingKits,代碼行數:33,代碼來源:NbtFactory.java

示例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();
}
 
開發者ID:bedatadriven,項目名稱:renjin-statet,代碼行數:19,代碼來源:LazyLoadFrame.java

示例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;
    }

  }

}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:33,代碼來源:FunctionConverter.java

示例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);
    }
}
 
開發者ID:asoem,項目名稱:greyfish,代碼行數:12,代碼來源:Persisters.java

示例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();
    }
}
 
開發者ID:elazarl,項目名稱:multireducers,代碼行數:16,代碼來源:MultiJobTest.java

示例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();
  }
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:9,代碼來源:JvmOptionsCodec.java

示例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();
  }
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:9,代碼來源:ArgumentsCodec.java

示例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
  
}
 
開發者ID:bedatadriven,項目名稱:renjin-statet,代碼行數:14,代碼來源:RParser.java

示例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);
  }
}
 
開發者ID:bedatadriven,項目名稱:renjin-statet,代碼行數:9,代碼來源:NamespaceDef.java

示例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();
  }
}
 
開發者ID:bedatadriven,項目名稱:renjin-statet,代碼行數:10,代碼來源:RDataReader.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:twill,代碼行數:6,代碼來源:ArgumentsCodec.java

示例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);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:44,代碼來源:DefaultBlobStore.java


注:本文中的com.google.common.io.InputSupplier.getInput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。