use of java.io.Reader in project sonarqube by SonarSource.
the class DefaultMetricsRepositoryLoader method loadFromPaginatedWs.
private void loadFromPaginatedWs(List<Metric> metrics) throws IOException {
int page = 1;
WsMetricsResponse response;
do {
GetRequest getRequest = new GetRequest(METRICS_SEARCH_URL + page);
try (Reader reader = wsClient.call(getRequest).contentReader()) {
response = GsonHelper.create().fromJson(reader, WsMetricsResponse.class);
for (WsMetric metric : response.metrics) {
metrics.add(new Metric.Builder(metric.getKey(), metric.getName(), ValueType.valueOf(metric.getType())).create().setDirection(metric.getDirection()).setQualitative(metric.isQualitative()).setUserManaged(metric.isCustom()).setDescription(metric.getDescription()).setId(metric.getId()));
}
}
page++;
} while (response.getP() < (response.getTotal() / response.getPs() + 1));
}
use of java.io.Reader in project sonarqube by SonarSource.
the class DefaultMetricsRepositoryLoaderTest method testIOError.
@Test
public void testIOError() throws IOException {
Reader reader = mock(Reader.class);
when(reader.read(any(char[].class), anyInt(), anyInt())).thenThrow(new IOException());
WsTestUtil.mockReader(wsClient, reader);
exception.expect(IllegalStateException.class);
metricsRepositoryLoader.load();
}
use of java.io.Reader in project Store by NYTimes.
the class JacksonReaderParserStoreTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Reader source = new StringReader(sourceString);
when(fetcher.fetch(barCode)).thenReturn(Observable.just(source));
when(persister.read(barCode)).thenReturn(Observable.<Reader>empty()).thenReturn(Observable.just(source));
when(persister.write(barCode, source)).thenReturn(Observable.just(true));
}
use of java.io.Reader in project feign by OpenFeign.
the class JacksonDecoder method decode.
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404)
return Util.emptyValueOf(type);
if (response.body() == null)
return null;
Reader reader = response.body().asReader();
if (!reader.markSupported()) {
reader = new BufferedReader(reader, 1);
}
try {
// Read the first byte to see if we have any data
reader.mark(1);
if (reader.read() == -1) {
// Eagerly returning null avoids "No content to map due to end-of-input"
return null;
}
reader.reset();
return mapper.readValue(reader, mapper.constructType(type));
} catch (RuntimeJsonMappingException e) {
if (e.getCause() != null && e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw e;
}
}
use of java.io.Reader in project OpenGrok by OpenGrok.
the class AnalyzerGuru method writeXref.
/**
* Write a browse-able version of the file
*
* @param factory The analyzer factory for this file type
* @param in The input stream containing the data
* @param out Where to write the result
* @param defs definitions for the source file, if available
* @param annotation Annotation information for the file
* @param project Project the file belongs to
* @throws java.io.IOException If an error occurs while creating the output
*/
public static void writeXref(FileAnalyzerFactory factory, Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
Reader input = in;
if (factory.getGenre() == Genre.PLAIN) {
// This is some kind of text file, so we need to expand tabs to
// spaces to match the project's tab settings.
input = ExpandTabsReader.wrap(in, project);
}
factory.writeXref(input, out, defs, annotation, project);
}
Aggregations