Search in sources :

Example 86 with Reader

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));
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) Reader(java.io.Reader) Metric(org.sonar.api.measures.Metric)

Example 87 with Reader

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();
}
Also used : Reader(java.io.Reader) StringReader(java.io.StringReader) IOException(java.io.IOException) Test(org.junit.Test)

Example 88 with Reader

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));
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Before(org.junit.Before)

Example 89 with Reader

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;
    }
}
Also used : BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) IOException(java.io.IOException) RuntimeJsonMappingException(com.fasterxml.jackson.databind.RuntimeJsonMappingException)

Example 90 with Reader

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);
}
Also used : HistoryReader(org.opensolaris.opengrok.history.HistoryReader) Reader(java.io.Reader) StringReader(java.io.StringReader)

Aggregations

Reader (java.io.Reader)1498 InputStreamReader (java.io.InputStreamReader)526 StringReader (java.io.StringReader)498 IOException (java.io.IOException)348 BufferedReader (java.io.BufferedReader)242 InputStream (java.io.InputStream)219 TokenStream (org.apache.lucene.analysis.TokenStream)171 Test (org.junit.Test)170 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)159 Connection (java.sql.Connection)137 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)126 FileReader (java.io.FileReader)108 FileInputStream (java.io.FileInputStream)107 File (java.io.File)105 BeforeClass (org.junit.BeforeClass)99 Tokenizer (org.apache.lucene.analysis.Tokenizer)91 SqlSession (org.apache.ibatis.session.SqlSession)83 StringWriter (java.io.StringWriter)81 ArrayList (java.util.ArrayList)77 Writer (java.io.Writer)63