Search in sources :

Example 36 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project snow-owl by b2ihealthcare.

the class SnomedRf2ImportRequest method read.

private void read(File rf2Archive, Rf2EffectiveTimeSlices slices, Rf2ValidationIssueReporter reporter) {
    final CsvMapper csvMapper = new CsvMapper();
    csvMapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
    final CsvSchema schema = CsvSchema.emptySchema().withoutQuoteChar().withColumnSeparator('\t').withLineSeparator("\r\n");
    final ObjectReader oReader = csvMapper.readerFor(String[].class).with(schema);
    final Stopwatch w = Stopwatch.createStarted();
    try (final ZipFile zip = new ZipFile(rf2Archive)) {
        for (ZipEntry entry : Collections.list(zip.entries())) {
            final String fileName = Paths.get(entry.getName()).getFileName().toString().toLowerCase();
            if (fileName.endsWith(TXT_EXT)) {
                if (fileName.contains(releaseType.toString().toLowerCase())) {
                    w.reset().start();
                    try (final InputStream in = zip.getInputStream(entry)) {
                        readFile(entry, in, oReader, slices, reporter);
                    }
                    log.info("{} - {}", entry.getName(), w);
                }
            }
        }
    } catch (IOException e) {
        throw new SnowowlRuntimeException(e);
    }
    slices.flushAll();
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ZipEntry(java.util.zip.ZipEntry) Stopwatch(com.google.common.base.Stopwatch) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 37 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project winery by eclipse.

the class MultiRepository method loadConfiguration.

/**
 * Reads the dependencies file into the repositoriesList.
 *
 * @param dependency The path to the dependencies file
 */
private List<RepositoryProperties> loadConfiguration(File dependency) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    ObjectReader reader = objectMapper.readerFor(new TypeReference<List<RepositoryProperties>>() {
    });
    return reader.readValue(dependency);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) List(java.util.List) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 38 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project Slide by ccrama.

the class LiveThread method doLiveThreadUpdates.

public void doLiveThreadUpdates() {
    final PaginatorAdapter adapter = new PaginatorAdapter(this);
    baseRecycler.setAdapter(adapter);
    doLiveSidebar();
    if (thread.getWebsocketUrl() != null && !thread.getWebsocketUrl().isEmpty()) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                final ObjectReader o = new ObjectMapper().reader();
                try {
                    WebSocket ws = new WebSocketFactory().createSocket(thread.getWebsocketUrl());
                    ws.addListener(new WebSocketAdapter() {

                        @Override
                        public void onTextMessage(WebSocket websocket, String s) {
                            LogUtil.v("Recieved" + s);
                            if (s.contains("\"type\": \"update\"")) {
                                try {
                                    LiveUpdate u = new LiveUpdate(o.readTree(s).get("payload").get("data"));
                                    updates.add(0, u);
                                    runOnUiThread(new Runnable() {

                                        @Override
                                        public void run() {
                                            adapter.notifyItemInserted(0);
                                            baseRecycler.smoothScrollToPosition(0);
                                        }
                                    });
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            } else if (s.contains("embeds_ready")) {
                                String node = updates.get(0).getDataNode().toString();
                                LogUtil.v("Getting");
                                try {
                                    node = node.replace("\"embeds\":[]", "\"embeds\":" + o.readTree(s).get("payload").get("media_embeds").toString());
                                    LiveUpdate u = new LiveUpdate(o.readTree(node));
                                    updates.set(0, u);
                                    runOnUiThread(new Runnable() {

                                        @Override
                                        public void run() {
                                            adapter.notifyItemChanged(0);
                                        }
                                    });
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        /* todoelse if(s.contains("delete")){
                                    updates.remove(0);
                                    adapter.notifyItemRemoved(0);
                                }*/
                        }
                    });
                    ws.connect();
                } catch (IOException | WebSocketException e) {
                    e.printStackTrace();
                }
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : IOException(java.io.IOException) WebSocketException(com.neovisionaries.ws.client.WebSocketException) IOException(java.io.IOException) WebSocket(com.neovisionaries.ws.client.WebSocket) LiveUpdate(net.dean.jraw.models.LiveUpdate) WebSocketAdapter(com.neovisionaries.ws.client.WebSocketAdapter) WebSocketFactory(com.neovisionaries.ws.client.WebSocketFactory) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 39 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project Slide by ccrama.

the class OfflineSubreddit method getSubreddit.

public static OfflineSubreddit getSubreddit(String subreddit, Long time, boolean offline, Context c) {
    if (cache == null)
        cache = new HashMap<>();
    String title;
    if (subreddit != null) {
        title = subreddit.toLowerCase(Locale.ENGLISH) + "," + time;
    } else {
        title = "";
        subreddit = "";
    }
    if (cache.containsKey(title)) {
        return cache.get(title);
    } else {
        subreddit = subreddit.toLowerCase(Locale.ENGLISH);
        OfflineSubreddit o = new OfflineSubreddit();
        o.subreddit = subreddit.toLowerCase(Locale.ENGLISH);
        if (time == 0) {
            o.base = true;
        }
        o.time = time;
        String[] split = Reddit.cachedData.getString(subreddit.toLowerCase(Locale.ENGLISH) + "," + time, "").split(",");
        if (split.length > 0) {
            o.time = time;
            o.submissions = new ArrayList<>();
            ObjectMapper mapperBase = new ObjectMapper();
            ObjectReader reader = mapperBase.reader();
            for (String s : split) {
                if (!s.contains("_"))
                    s = "t3_" + s;
                if (!s.isEmpty()) {
                    try {
                        Submission sub = getSubmissionFromStorage(s, c, offline, reader);
                        if (sub != null) {
                            o.submissions.add(sub);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        } else {
            o.submissions = new ArrayList<>();
        }
        cache.put(title, o);
        return o;
    }
}
Also used : Submission(net.dean.jraw.models.Submission) HashMap(java.util.HashMap) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 40 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project eap-additional-testsuite by jboss-set.

the class Jsr310DeserializationTestCase method testDurationDeserialization.

@Test
public void testDurationDeserialization() throws Exception {
    ObjectReader reader = new ObjectMapper().registerModule(new JavaTimeModule()).readerFor(Duration.class);
    final String INPUT = "1e10000000";
    // this should return almost instantly
    Duration value = reader.without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS).readValue(INPUT);
    Assert.assertEquals("Didn't get the expected value.", 0, value.getSeconds());
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Duration(java.time.Duration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectReader (com.fasterxml.jackson.databind.ObjectReader)83 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 IOException (java.io.IOException)32 Test (org.junit.Test)23 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ArrayList (java.util.ArrayList)8 JavaType (com.fasterxml.jackson.databind.JavaType)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)4 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)4 Method (java.lang.reflect.Method)4 Collectors (java.util.stream.Collectors)4 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)3 JSONLayoutPage (org.knime.js.core.layout.bs.JSONLayoutPage)3