本文整理匯總了Java中com.google.common.io.CharStreams.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java CharStreams.toString方法的具體用法?Java CharStreams.toString怎麽用?Java CharStreams.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.io.CharStreams
的用法示例。
在下文中一共展示了CharStreams.toString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleError
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
@Override
public void handleError(ClientHttpResponse response) throws IOException {
String seyrenResponseBody;
LOGGER.debug("Response : {} {}", response.getStatusCode(), response.getStatusText());
if (response.getBody() != null) {
seyrenResponseBody = CharStreams.toString(new InputStreamReader(response.getBody(), "UTF-8"));
} else {
seyrenResponseBody = "Response whithout body";
}
CerebroException exception = new CerebroException(ErrorCode.SEYREN_ERROR, seyrenResponseBody);
throw exception;
}
示例2: verifyTarArchive
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
/**
* Helper method to verify that the files were archived correctly by reading {@code
* tarArchiveInputStream}.
*/
private void verifyTarArchive(TarArchiveInputStream tarArchiveInputStream) throws IOException {
// Verifies fileA was archived correctly.
TarArchiveEntry headerFileA = tarArchiveInputStream.getNextTarEntry();
Assert.assertEquals("some/path/to/resourceFileA", headerFileA.getName());
String fileAString =
CharStreams.toString(new InputStreamReader(tarArchiveInputStream, StandardCharsets.UTF_8));
Assert.assertEquals(expectedFileAString, fileAString);
// Verifies fileB was archived correctly.
TarArchiveEntry headerFileB = tarArchiveInputStream.getNextTarEntry();
Assert.assertEquals("crepecake", headerFileB.getName());
String fileBString =
CharStreams.toString(new InputStreamReader(tarArchiveInputStream, StandardCharsets.UTF_8));
Assert.assertEquals(expectedFileBString, fileBString);
// Verifies directoryA was archived correctly.
TarArchiveEntry headerDirectoryA = tarArchiveInputStream.getNextTarEntry();
Assert.assertEquals("some/path/to/", headerDirectoryA.getName());
Assert.assertNull(tarArchiveInputStream.getNextTarEntry());
}
示例3: readModifedTimeInCacheForFile
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
private long readModifedTimeInCacheForFile (File file,String key) throws IOException {
InputStream in = new FileInputStream(file);
try {
Reader reader = new InputStreamReader(in);
String text = CharStreams.toString(reader);
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(text);
JsonObject jsonCache = je.getAsJsonObject();
JsonElement elt = jsonCache.get(key);
JsonObject generatedObj = elt.getAsJsonObject();
long modified = generatedObj.get("modified").getAsLong();
return modified;
} finally {
if (in!=null) in.close();
}
}
示例4: testCloudStorageSignUrl
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
@Test
public void testCloudStorageSignUrl() throws IOException {
StorageClient storage = StorageClient.getInstance(IntegrationTestUtils.ensureDefaultApp());
Bucket bucket = storage.bucket();
Blob blob = createTextBlob(bucket, "Signed URL Test");
URL url = blob.signUrl(3600, TimeUnit.SECONDS);
try (InputStream in = url.openStream()) {
String result = CharStreams.toString(new InputStreamReader(in));
assertEquals("Signed URL Test", result);
} finally {
blob.delete();
}
}
示例5: readResource
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
public static String readResource(String resourceFile) {
try (InputStreamReader reader = new InputStreamReader(GetViewRequestExecutor.class.getResourceAsStream(resourceFile), StandardCharsets.UTF_8)) {
return CharStreams.toString(reader);
} catch (IOException e) {
throw new RuntimeException("Could not find resource " + resourceFile, e);
}
}
示例6: getContentsFromFileEntry
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
/***/
public static String getContentsFromFileEntry(final ZipEntry entry, String rootName) throws IOException,
URISyntaxException {
URL rootURL = Thread.currentThread().getContextClassLoader().getResource(rootName);
try (final ZipFile root = new ZipFile(new File(rootURL.toURI()));) {
InputSupplier<InputStreamReader> readerSupplier = CharStreams.newReaderSupplier(
new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return root.getInputStream(entry);
}
}, Charsets.UTF_8);
return CharStreams.toString(readerSupplier);
}
}
示例7: readScript
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
@Override
public String readScript() {
try {
return CharStreams.toString(new InputStreamReader(storage.readBinaryData(info.getId(), SCRIPT_CONTENT).orElseThrow(AssertionError::new), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例8: post
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
@Override
public String post(final HttpServletRequest req, final HttpServletResponse res) {
String result = "";
try {
final String body = CharStreams.toString(req.getReader());
final JsonParser jsonParser = new JsonParser();
final JsonObject jsonReq = jsonParser.parse(body).getAsJsonObject();
if (!jsonReq.has(TYPE)) {
LOG.warn("no type in JSON");
} else {
final JsonElement typeJsonElement = jsonReq.get(TYPE);
final String type = typeJsonElement.getAsString();
switch (type) {
case URL_VERIFICATION:
result = handleUrlVerification(jsonReq, res);
break;
case EVENT_CALLBACK:
handleEvent(jsonReq, res);
break;
default:
LOG.info("unknown type {}", type);
break;
}
}
} catch (final Exception e) {
handleException(e);
}
return result;
}
示例9: readContent
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
private static String readContent(InputStream stream) throws IOException {
if (stream != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
try {
return CharStreams.toString(reader);
} finally {
reader.close();
}
}
return null;
}
示例10: testAsBufferedReader
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
@Test
public void testAsBufferedReader() throws IOException {
String expected = "hello\nworld\n";
BufferedReader reader = Resources.asBufferedReader("resources-test/hello.txt");
String actual = CharStreams.toString(reader);
assertEquals(expected, actual);
}
示例11: doLoad
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
@Override
protected void doLoad ( final InputStream inputStream, final Map<?, ?> options ) throws IOException
{
try
{
final String data = CharStreams.toString ( new InputStreamReader ( inputStream, this.defaultCharacterSet ) );
getContents ().add ( parse ( data ) );
}
finally
{
inputStream.close ();
}
}
示例12: createContent
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
public static ContentProvider createContent ( final InputStream resource, final Map<String, String> replacements, final Pattern pattern ) throws IOException
{
try
{
String str = CharStreams.toString ( new InputStreamReader ( resource, StandardCharsets.UTF_8 ) );
str = StringReplacer.replace ( str, StringReplacer.newSource ( replacements ), pattern );
return new StaticContentProvider ( str );
}
finally
{
resource.close ();
}
}
示例13: createFile
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
protected static void createFile ( final File file, final InputStream resource, final Map<String, String> replacements, final IProgressMonitor monitor, final Pattern pattern ) throws Exception
{
try
{
String str = CharStreams.toString ( new InputStreamReader ( resource, StandardCharsets.UTF_8 ) );
str = StringReplacer.replace ( str, StringReplacer.newSource ( replacements ), pattern );
createFile ( file, str, monitor );
}
finally
{
resource.close ();
}
}
示例14: getFileAsString
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
protected static String getFileAsString(String path) {
LOG.debug("Loading file: {}", path);
try {
return CharStreams.toString(new InputStreamReader(BaseHttpTest.class.getClassLoader().getResourceAsStream(path), Charsets.UTF_8));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例15: loadFile
import com.google.common.io.CharStreams; //導入方法依賴的package包/類
String loadFile(String simpleFileName) throws IOException {
InputStream is = ParserCompressorFragmentTest.class.getResourceAsStream(simpleFileName);
try (Reader in = new InputStreamReader(is, Charsets.UTF_8)) {
return CharStreams.toString(in);
}
}