Android Open Source - bike-friend You Bike Station C S V Parser V1






From Project

Back to project page bike-friend.

License

The source code is released under:

GNU General Public License

If you think the Android project bike-friend listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lemoulinstudio.bikefriend.ubike;
//  ww  w .  ja v a 2  s . co m
import com.google.android.gms.maps.model.LatLng;
import com.lemoulinstudio.bikefriend.StationParser;
import com.lemoulinstudio.bikefriend.ParsingException;
import com.lemoulinstudio.bikefriend.Utils;
import java.io.InputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import android.util.Log;

/**
 * This parser extracts information from a data source in a format similar to CSV.
 * In this format, the lines are separated by a "|" and the values are separated by a "_".
 *
 * @author Vincent Cantin
 */
public class YouBikeStationCSVParserV1 implements StationParser<YouBikeStation> {

  @Override
  public List<YouBikeStation> parse(InputStream in) throws IOException, ParsingException {
    List<YouBikeStation> result = new ArrayList<YouBikeStation>();
    
    try {
      Date now = new Date();
      
      String rawData = Utils.readToString(in);
      String[] lines = rawData.split("\\|");
      for (String line : lines) {
        //Log.i("bikefriend", "line = " + line);
        String[] elements = line.split("_", -1);
        //Log.i("bikefriend", "elements = " + Arrays.toString(elements));
        
        if (elements.length >= 11) {
          YouBikeStation station = new YouBikeStation();
          station.id = elements[0];
          station.chineseName = elements[1];
          station.nbTotalPlaces = Integer.parseInt(elements[2]);
          station.nbBikes = Integer.parseInt(elements[3]);
          station.location = new LatLng(
                    Double.parseDouble(elements[5]),
                    Double.parseDouble(elements[6]));
          station.chineseAddress = elements[7];
          station.englishName = elements[9];
          station.englishAddress = elements[10];

          station.nbEmptySlots = station.nbTotalPlaces - station.nbBikes;
          station.date = now;
          station.isTestStation = false;

          result.add(station);
        }
      }
    }
    catch (Exception e) {
      throw new ParsingException(e);
    }
    finally {
      in.close();
    }
    
    return result;
  }
  
}




Java Source Code List

com.lemoulinstudio.bikefriend.InternetStationProvider.java
com.lemoulinstudio.bikefriend.ParsingException.java
com.lemoulinstudio.bikefriend.StationInfoWindowAdapter.java
com.lemoulinstudio.bikefriend.StationMapActivity.java
com.lemoulinstudio.bikefriend.StationParser.java
com.lemoulinstudio.bikefriend.StationProvider.java
com.lemoulinstudio.bikefriend.Station.java
com.lemoulinstudio.bikefriend.Utils.java
com.lemoulinstudio.bikefriend.cbike.CBikeStationXmlParserV1.java
com.lemoulinstudio.bikefriend.cbike.CBikeStation.java
com.lemoulinstudio.bikefriend.cbike.KaohsiungStationProvider.java
com.lemoulinstudio.bikefriend.ubike.ChanghuaStationProvider.java
com.lemoulinstudio.bikefriend.ubike.TaichungStationProvider.java
com.lemoulinstudio.bikefriend.ubike.TaipeiStationProvider.java
com.lemoulinstudio.bikefriend.ubike.YouBikeStationCSVParserV1.java
com.lemoulinstudio.bikefriend.ubike.YouBikeStationHtmlParserV2.java
com.lemoulinstudio.bikefriend.ubike.YouBikeStationJsonParserV1.java
com.lemoulinstudio.bikefriend.ubike.YouBikeStation.java
com.lemoulinstudio.bikefriend.webapp.StationParser.java
com.lemoulinstudio.bikefriend.webapp.cbike.BIKEStationData.java
com.lemoulinstudio.bikefriend.webapp.cbike.BIKEStation.java
com.lemoulinstudio.bikefriend.webapp.cbike.CBikeStationParser.java
com.lemoulinstudio.bikefriend.webapp.cbike.XmlStation.java
com.lemoulinstudio.bikefriend.webapp.conf.ShutdownHook.java
com.lemoulinstudio.bikefriend.webapp.conf.StartupHook.java
com.lemoulinstudio.bikefriend.webapp.entity.StationLog.java
com.lemoulinstudio.bikefriend.webapp.entity.Station.java
com.lemoulinstudio.bikefriend.webapp.io.InputStreamSequence.java
com.lemoulinstudio.bikefriend.webapp.io.IntArrayInputStream.java
com.lemoulinstudio.bikefriend.webapp.quartz.LoadStationDataJob.java
com.lemoulinstudio.bikefriend.webapp.rest.StationResource.java
com.lemoulinstudio.bikefriend.webapp.ubike.MarkerList.java
com.lemoulinstudio.bikefriend.webapp.ubike.Marker.java
com.lemoulinstudio.bikefriend.webapp.ubike.YouBikeStationParser.java
com.lemoulinstudio.bikefriend.webapp.vo.StationLogVo.java
com.lemoulinstudio.bikefriend.webapp.vo.StationVo.java