Package org.apache.pivot.serialization

Examples of org.apache.pivot.serialization.CSVSerializer


        // v - volume
        String symbolsArgument = symbolsArgumentBuilder.toString();
        getQuery.getParameters().put("s", symbolsArgument);
        getQuery.getParameters().put("f", "snl1ohgc1v");

        CSVSerializer quoteSerializer = new CSVSerializer();
        quoteSerializer.getKeys().add("symbol");
        quoteSerializer.getKeys().add("companyName");
        quoteSerializer.getKeys().add("value");
        quoteSerializer.getKeys().add("openingValue");
        quoteSerializer.getKeys().add("highValue");
        quoteSerializer.getKeys().add("lowValue");
        quoteSerializer.getKeys().add("change");
        quoteSerializer.getKeys().add("volume");

        quoteSerializer.setItemClass(StockQuote.class);
        getQuery.setSerializer(quoteSerializer);

        getQuery.execute(new TaskAdapter<Object>(new TaskListener<Object>() {
            @Override
            public void taskExecuted(Task<Object> task) {
View Full Code Here


            // v - volume
            String symbolsParameter = symbolsParameterBuilder.toString();
            getQuery.getParameters().put("s", symbolsParameter);
            getQuery.getParameters().put("f", "snl1ohgc1v");

            CSVSerializer quoteSerializer = new CSVSerializer(StockQuote.class);
            quoteSerializer.setKeys("symbol",
                "companyName",
                "value",
                "openingValue",
                "highValue",
                "lowValue",
View Full Code Here

                InputStream inputStream = null;

                try {
                    inputStream = new MonitoredInputStream(fileURL.openStream());

                    CSVSerializer csvSerializer = new CSVSerializer();
                    csvSerializer.setKeys("c0", "c1", "c2", "c3");
                    csvSerializer.getCSVSerializerListeners().add(new CSVSerializerListener.Adapter() {
                        private ArrayList<Object> page = new ArrayList<Object>(pageSize);

                        @Override
                        public void endList(CSVSerializer csvSerializerArgument) {
                            if (page.getLength() > 0) {
                                ApplicationContext.queueCallback(new AddRowsCallback(page));
                            }
                        }

                        @Override
                        public void readItem(CSVSerializer csvSerializerArgument, Object item) {
                            page.add(item);

                            if (page.getLength() == pageSize) {
                                ApplicationContext.queueCallback(new AddRowsCallback(page));
                                page = new ArrayList<Object>(pageSize);
                            }
                        }
                    });

                    csvSerializer.readObject(inputStream);
                } finally {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                }
View Full Code Here

        buf.append("a3,b3,c3\r");
        buf.append("a4,b4,c4");

        StringReader reader = new StringReader(buf.toString());

        CSVSerializer serializer = new CSVSerializer();
        serializer.setKeys("A", "B", "C");
        serializer.getCSVSerializerListeners().add(new CSVSerializerListener() {
            @Override
            public void beginList(CSVSerializer csvSerializer, List<?> list) {
                System.out.println("Begin list: " + list);
            }

            @Override
            public void endList(CSVSerializer csvSerializer) {
                System.out.println("End list");
            }

            @Override
            public void readItem(CSVSerializer csvSerializer, Object item) {
                System.out.println("Read item: " + item);
            }
        });

        List<?> result = serializer.readObject(reader);

        Dictionary<String, Object> row;

        // Test the first row
        row = (Dictionary<String, Object>)result.get(0);
View Full Code Here

        StringBuilder buf = new StringBuilder();
        buf.append("a,\",b,\",c\r\n");

        StringReader reader = new StringReader(buf.toString());

        CSVSerializer serializer = new CSVSerializer();
        serializer.setKeys("A", "B", "C");

        List<?> result = serializer.readObject(reader);

        Dictionary<String, Object> row = (Dictionary<String, Object>)result.get(0);
        assertEquals("a", row.get("A"));
        assertEquals(",b,", row.get("B"));
        assertEquals("c", row.get("C"));
View Full Code Here

        StringBuilder buf = new StringBuilder();
        buf.append("a,\"\"\"b\"\"\",c\r\n");

        StringReader reader = new StringReader(buf.toString());

        CSVSerializer serializer = new CSVSerializer();
        serializer.setKeys("A", "B", "C");

        List<?> result = serializer.readObject(reader);

        Dictionary<String, Object> row = (Dictionary<String, Object>)result.get(0);
        assertEquals("a", row.get("A"));
        assertEquals("\"b\"", row.get("B"));
        assertEquals("c", row.get("C"));
View Full Code Here

        StringBuilder buf = new StringBuilder();
        buf.append("a,\"b\nb  \",c\r\n");

        StringReader reader = new StringReader(buf.toString());

        CSVSerializer serializer = new CSVSerializer();
        serializer.setKeys("A", "B", "C");

        List<?> result = serializer.readObject(reader);

        Dictionary<String, Object> row = (Dictionary<String, Object>)result.get(0);
        assertEquals("a", row.get("A"));
        assertEquals("b\nb", row.get("B"));
        assertEquals("c", row.get("C"));
View Full Code Here

            new Dictionary.Pair<String, Object>("C", "c2")
        ));

        StringWriter writer = new StringWriter();

        CSVSerializer serializer = new CSVSerializer();
        serializer.setKeys("A", "B", "C");

        serializer.writeObject(items, writer);

        assertEquals("a1,b1,c1\r\na2,b2,c2\r\n", writer.toString());
    }
View Full Code Here

            new Dictionary.Pair<String, Object>("C", "c")
        ));

        StringWriter writer = new StringWriter();

        CSVSerializer serializer = new CSVSerializer();
        serializer.setKeys("A", "B", "C");

        serializer.writeObject(items, writer);

        assertEquals("a,\",b,\",c\r\n", writer.toString());
    }
View Full Code Here

            new Dictionary.Pair<String, Object>("C", "c")
        ));

        StringWriter writer = new StringWriter();

        CSVSerializer serializer = new CSVSerializer();
        serializer.setKeys("A", "B", "C");

        serializer.writeObject(items, writer);

        assertEquals("a,\"\"\"b\"\"\",c\r\n", writer.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.pivot.serialization.CSVSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.