Code example for DataInputStream

Methods: readDouble, readUTF

0
    public static Address deserializeAddress(byte[] buffer) throws IOException {
        if (buffer == null)
            return null; 
 
        final ByteArrayInputStream buf = new ByteArrayInputStream(buffer);
        final DataInputStream in = new DataInputStream(buf);
        return deserializeAddress(in);
    } 
 
    public static Address deserializeAddress(DataInputStream in)
    throws IOException { 
        /* 
         * longitude 
         * latitude 
         * admin area 
         * sub admin area 
         * locality 
         * thoroughfare 
         * feature name 
         */ 
        final Address a = new Address(Locale.getDefault());
 
        a.setLongitude(in.readDouble());
        a.setLatitude(in.readDouble());
        final String admin = in.readUTF();
        final String subAdmin = in.readUTF();
        final String locality = in.readUTF();
        final String thoroughfare = in.readUTF();
        final String feature = in.readUTF();
 
        if (admin.length() > 0)
            a.setAdminArea(admin);
        if (subAdmin.length() > 0)
            a.setSubAdminArea(subAdmin);