本文整理汇总了Java中org.apache.commons.io.input.ReaderInputStream类的典型用法代码示例。如果您正苦于以下问题:Java ReaderInputStream类的具体用法?Java ReaderInputStream怎么用?Java ReaderInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReaderInputStream类属于org.apache.commons.io.input包,在下文中一共展示了ReaderInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetAllTagsPatient
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testGetAllTagsPatient() throws Exception {
TagList tagList = new TagList();
tagList.add(new Tag("CCC", "AAA", "BBB"));
String ser = ctx.newXmlParser().encodeTagListToString(tagList);
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ser), Charset.forName("UTF-8")));
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
TagList response = client.getAllTagsPatient();
assertEquals(tagList, response);
assertEquals(HttpGet.class, capt.getValue().getClass());
HttpGet get = (HttpGet) capt.getValue();
assertEquals("http://foo/Patient/_tags", get.getURI().toString());
}
示例2: assertInputConversion_viaCharsetName
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
private void assertInputConversion_viaCharsetName(String charsetName, boolean conversionErrorsExpected)
throws Exception {
byte[] originalBytes = createBytes();
{
// byte array as byte stream
InputStream originalByteStream = new ByteArrayInputStream(originalBytes);
// byte stream as character stream
Reader originalReader = new InputStreamReader(originalByteStream, charsetName);
// modifying reader (we don't modify here)
Reader modifyingReader = new ModifyingReader(originalReader, new RegexModifier("a", 0, "a"));
// character stream as byte stream
InputStream modifyingByteStream = new ReaderInputStream(modifyingReader, charsetName);
// byte stream as byte array
byte[] modifiedBytes = IOUtils.toByteArray(modifyingByteStream);
assertBytes(originalBytes, modifiedBytes, conversionErrorsExpected);
}
}
示例3: rewriteContent
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
/**
* @param flush
* @return Returns true if the actual output is equals to the expected
* output.
* @throws Exception
*/
private boolean rewriteContent(boolean flush, String domainPrefix) throws Exception {
String contentPart = StringUtils.repeat("text", 2);
String oldUrl = domainPrefix + "something";
String expectedNewUrl = domainPrefix + "anything";
String oldHtml = "<html><body>" + contentPart + oldUrl + contentPart + "</body></html>";
String expectedNewHtml = "<html><body>" + contentPart + expectedNewUrl + contentPart + "</body></html>";
String encoding = "UTF-8";
ByteArrayOutputStream os = new ByteArrayOutputStream();
long written = rewriteContent(new ReaderInputStream(new StringReader(oldHtml)), os, encoding, flush);
System.out.println("written: " + written);
System.out.println("oldHtml.length(): " + oldHtml.length());
System.out.println("expectedNewHtml.length(): " + expectedNewHtml.length());
System.out.println("expectedNewHtml: \n" + expectedNewHtml);
os.flush();
String newHtml = new String(os.toByteArray(), encoding);
System.out.println(newHtml);
return expectedNewHtml.equals(newHtml);
}
示例4: getInputStreamFromJar
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
private static InputStream getInputStreamFromJar(final InputStream jarInputStream,
final String prefix,
final String suffix) throws IOException {
ZipInputStream zis = new ZipInputStream(jarInputStream);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
final String entryName = entry.getName();
if (entryName.startsWith(prefix) && entryName.endsWith(suffix)) {
return new ReaderInputStream( new InputStreamReader( zis,
"UTF-8"));
}
}
throw new FileNotFoundException("Could not find '" + prefix + "/*/" + suffix + "' in the jar.");
}
示例5: testAddTagsPatientVersion
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testAddTagsPatientVersion() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(httpResponse.getEntity().getContentType().getElements()).thenReturn(new HeaderElement[0]);
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
TagList tagList = new TagList();
tagList.add(new Tag("CCC", "AAA", "BBB"));
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
client.addTags(new IdDt("111"), new IdDt("222"),tagList);
assertEquals(HttpPost.class, capt.getValue().getClass());
HttpPost post = (HttpPost) capt.getValue();
assertEquals("http://foo/Patient/111/_history/222/_tags", post.getURI().toString());
String ser = IOUtils.toString(post.getEntity().getContent());
TagList actualTagList = ctx.newXmlParser().parseTagList(ser);
assertEquals(tagList, actualTagList);
}
示例6: testTransaction
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testTransaction() throws Exception {
String bundleStr = IOUtils.toString(getClass().getResourceAsStream("/bundle.json"));
Bundle bundle = ourCtx.newJsonParser().parseBundle(bundleStr);
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(bundleStr), Charset.forName("UTF-8")));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
//@formatter:off
Bundle response = client.transaction()
.withBundle(bundle)
.execute();
//@formatter:on
assertEquals("http://example.com/fhir", capt.getValue().getURI().toString());
assertEquals(bundle.getEntries().get(0).getId(), response.getEntries().get(0).getId());
assertEquals(EncodingEnum.XML.getBundleContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(0).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
}
示例7: testDeleteTagsPatientVersion
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testDeleteTagsPatientVersion() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(httpResponse.getEntity().getContentType().getElements()).thenReturn(new HeaderElement[0]);
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
TagList tagList = new TagList();
tagList.add(new Tag("CCC", "AAA", "BBB"));
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
client.deleteTags(new IdDt("111"), new IdDt("222"),tagList);
assertEquals(HttpPost.class, capt.getValue().getClass());
HttpPost post = (HttpPost) capt.getValue();
assertEquals("http://foo/Patient/111/_history/222/_tags/_delete", post.getURI().toString());
String ser = IOUtils.toString(post.getEntity().getContent());
TagList actualTagList = ctx.newXmlParser().parseTagList(ser);
assertEquals(tagList, actualTagList);
}
示例8: testCreateBad
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testCreateBad() throws Exception {
Patient patient = new Patient();
patient.addIdentifier("urn:foo", "123");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 400, "foobar"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("foobar"), Charset.forName("UTF-8")));
try {
ctx.newRestfulClient(ITestClient.class, "http://foo").createPatient(patient);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), StringContains.containsString("foobar"));
}
}
示例9: testSearchByString
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testSearchByString() throws Exception {
String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
//@formatter:off
Bundle response = client.search()
.forResource("Patient")
.where(Patient.NAME.matches().value("james"))
.execute();
//@formatter:on
assertEquals("http://example.com/fhir/Patient?name=james", capt.getValue().getURI().toString());
assertEquals(Patient.class, response.getEntries().get(0).getResource().getClass());
}
示例10: testSearchWithClientEncodingAndPrettyPrintConfig
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@SuppressWarnings("unused")
@Test
public void testSearchWithClientEncodingAndPrettyPrintConfig() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
GenericClient client = (GenericClient) ourCtx.newRestfulGenericClient("http://example.com/fhir");
client.setPrettyPrint(true);
client.setEncoding(EncodingEnum.JSON);
//@formatter:off
Bundle response = client.search()
.forResource(Patient.class)
.execute();
//@formatter:on
assertEquals("http://example.com/fhir/Patient?_format=json&_pretty=true", capt.getValue().getURI().toString());
}
示例11: testDelete
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testDelete() throws Exception {
OperationOutcome oo = new OperationOutcome();
oo.addIssue().setDetails("Hello");
String resp = new FhirContext().newXmlParser().encodeResourceToString(oo);
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(resp), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.deletePatient(new IdDt("1234"));
assertEquals(HttpDelete.class, capt.getValue().getClass());
assertEquals("http://foo/Patient/1234", capt.getValue().getURI().toString());
assertEquals("Hello", response.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue());
}
示例12: testSearchWithAbsoluteUrlAndType
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testSearchWithAbsoluteUrlAndType() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
Bundle response = client
.search(Patient.class,
new UriDt(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json"));
assertEquals(
"http://example.com/fhir/Patient?birthdate=%3C%3D2012-01-22&birthdate=%3E2011-01-01&_include=Patient.managingOrganization&_sort%3Aasc=birthdate&_sort%3Adesc=name&_count=123&_format=json",
capt.getValue().getURI().toString());
assertEquals(1, response.size());
}
示例13: testReadFailureInternalError
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testReadFailureInternalError() throws Exception {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 500, "INTERNAL"));
Header[] headers = new Header[1];
headers[0] = new BasicHeader(Constants.HEADER_LAST_MODIFIED, "2011-01-02T22:01:02");
when(httpResponse.getAllHeaders()).thenReturn(headers);
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("Internal Failure"), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
try {
client.getPatientById(new IdDt("111"));
fail();
} catch (InternalErrorException e) {
assertThat(e.getMessage(), containsString("INTERNAL"));
assertThat(e.getResponseBody(), containsString("Internal Failure"));
}
}
示例14: testReadFailureNoCharset
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testReadFailureNoCharset() throws Exception {
//@formatter:off
String msg = "<OperationOutcome xmlns=\"http://hl7.org/fhir\"></OperationOutcome>";
//@formatter:on
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 404, "NOT FOUND"));
Header[] headers = new Header[1];
headers[0] = new BasicHeader(Constants.HEADER_LAST_MODIFIED, "2011-01-02T22:01:02");
when(httpResponse.getAllHeaders()).thenReturn(headers);
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
try {
client.getPatientById(new IdDt("111"));
fail();
} catch (ResourceNotFoundException e) {
// good
}
}
示例15: testSearchByDateRange
import org.apache.commons.io.input.ReaderInputStream; //导入依赖的package包/类
@Test
public void testSearchByDateRange() throws Exception {
String msg = getPatientFeedWithOneResult();
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
DateRangeParam param = new DateRangeParam();
param.setLowerBound(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-01"));
param.setUpperBound(new DateParam(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS, "2021-01-01"));
client.getPatientByDateRange(param);
assertEquals("http://foo/Patient?dateRange=%3E%3D2011-01-01&dateRange=%3C%3D2021-01-01", capt.getValue().getURI().toString());
}