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


Java CharStreams.toString方法代碼示例

本文整理匯總了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;
}
 
開發者ID:voyages-sncf-technologies,項目名稱:cerebro,代碼行數:13,代碼來源:SeyrenResponseErrorHandler.java

示例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());
}
 
開發者ID:GoogleCloudPlatform,項目名稱:minikube-build-tools-for-java,代碼行數:26,代碼來源:TarStreamBuilderTest.java

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

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

示例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);
    }
}
 
開發者ID:gocd,項目名稱:kubernetes-elastic-agents,代碼行數:8,代碼來源:Util.java

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

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

示例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;
}
 
開發者ID:nitroventures,項目名稱:bot4j,代碼行數:34,代碼來源:SlackEventWebhookImpl.java

示例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;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:12,代碼來源:YoungAndroidProjectService.java

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

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

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

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

示例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);
    }
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:10,代碼來源:BaseHttpTest.java

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


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