Package com.urbanairship.datacube.backfill

Examples of com.urbanairship.datacube.backfill.CollectionWritable


    }
   
    public static <T extends Writable> String toBase64(Class<T> valueClass,
            Collection<? extends Writable> collection) throws IOException {
        DataOutputBuffer out = new DataOutputBuffer();
        new CollectionWritable(valueClass, collection).write(out);
        byte[] rawBytes = Arrays.copyOf(out.getData(), out.getLength());
        return new String(Base64.encodeBase64(rawBytes));
    }
View Full Code Here


            String base64) throws IOException {
        byte[] rawBytes = Base64.decodeBase64(base64.getBytes());
        DataInputBuffer in = new DataInputBuffer();
        in.reset(rawBytes, rawBytes.length);
       
        CollectionWritable cw = new CollectionWritable();
        cw.readFields(in);
        return (Collection<T>)cw.getCollection();
    }
View Full Code Here

        List<IntWritable> list = new ArrayList<IntWritable>();
        list.add(new IntWritable(1));
        list.add(new IntWritable(2));
        list.add(new IntWritable(3));
       
        CollectionWritable c = new CollectionWritable(IntWritable.class, list);
       
        DataOutputBuffer buf = new DataOutputBuffer();
        c.write(buf);
       
        DataInputBuffer in = new DataInputBuffer();
        in.reset(buf.getData(), buf.getLength());
        CollectionWritable roundTripped = new CollectionWritable();
        roundTripped.readFields(in);
       
        Assert.assertEquals(list, roundTripped.getCollection());
        Iterator<? extends Writable> it = roundTripped.getCollection().iterator();
        Assert.assertEquals(new IntWritable(1), it.next());
        Assert.assertEquals(new IntWritable(2), it.next());
        Assert.assertEquals(new IntWritable(3), it.next());
        Assert.assertTrue(!it.hasNext());
    }
View Full Code Here

   
    @Test
    public void emptyCollection() throws Exception {
        Collection<Scan> scans = new HashSet<Scan>();
        DataOutputBuffer buf = new DataOutputBuffer();
        CollectionWritable c = new CollectionWritable(Scan.class, scans);
        c.write(buf);
       
        DataInputBuffer in = new DataInputBuffer();
        in.reset(buf.getData(), buf.getLength());
        CollectionWritable roundTripped = new CollectionWritable();
        roundTripped.readFields(in);
       
        Assert.assertEquals(0, roundTripped.getCollection().size());
    }
View Full Code Here

TOP

Related Classes of com.urbanairship.datacube.backfill.CollectionWritable

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.