Package org.apache.pivot.serialization

Examples of org.apache.pivot.serialization.CSVSerializer


            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,\"\nb\n\",c\r\n", writer.toString());
    }
View Full Code Here


        buf.append("A \t, B ,C \n");
        buf.append("a1,b1,c1\n");

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

        CSVSerializer serializer = new CSVSerializer();
        List<?> result = serializer.readObject(reader);
        Dictionary<String, Object> row = (Dictionary<String, Object>)result.get(0);
        assertEquals(row.get("A"), "a1");
        assertEquals(row.get("B"), "b1");
        assertEquals(row.get("C"), "c1");
    }
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 csvSerializer) {
                            if (page.getLength() > 0) {
                                ApplicationContext.queueCallback(new AddRowsCallback(page));
                            }
                        }

                        @Override
                        public void readItem(CSVSerializer csvSerializer, 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

                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 csvSerializer) {
                            if (page.getLength() > 0) {
                                ApplicationContext.queueCallback(new AddRowsCallback(page));
                            }
                        }

                        @Override
                        public void readItem(CSVSerializer csvSerializer, 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

    private static int nextID = 0;

    @Override
    @SuppressWarnings("unchecked")
    public void init() throws ServletException {
        CSVSerializer expenseSerializer = new CSVSerializer(Expense.class);
        expenseSerializer.setKeys("date", "type", "amount", "description");

        // Load the initial expense data
        InputStream inputStream = ExpenseServlet.class.getResourceAsStream("expenses.csv");

        try {
            expenses = (List<Expense>)expenseSerializer.readObject(inputStream);
        } catch (IOException exception) {
            throw new ServletException(exception);
        } catch (SerializationException exception) {
            throw new ServletException(exception);
        }
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

        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() {
            public void beginList(CSVSerializer csvSerializer, List<?> list) {
                System.out.println("Begin list: " + list);
            }

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

            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

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.