Android Open Source - bike-friend Input Stream Sequence






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.webapp.io;
//from  www.j a v  a 2  s  . c  o m
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

/**
 *
 * @author Vincent Cantin
 */
public class InputStreamSequence extends InputStream {
  
  private final Iterator<InputStream> it;
  private InputStream in;

  public InputStreamSequence(Iterator<InputStream> it) {
    this.it = it;
  }

  @Override
  public int available() throws IOException {
    if (in == null) {
      if (it.hasNext()) {
        in = it.next();
      }
      else {
        return 0;
      }
    }
    
    return in.available();
  }

  @Override
  public long skip(long n) throws IOException {
    if (in == null) {
      if (it.hasNext()) {
        in = it.next();
      }
      else {
        return 0;
      }
    }
    
    long remaining = n;
    
    while (true) {
      long skipped = in.skip(remaining);
      remaining -= skipped;
      
      if (remaining > 0) {
        in.close();
        
        if (it.hasNext()) {
          in = it.next();
        }
        else {
          break;
        }
      }
    }
    
    return n - remaining;
  }

  @Override
  public int read(byte[] b, int off, int len) throws IOException {
    if (in == null) {
      if (it.hasNext()) {
        in = it.next();
      }
      else {
        return 0;
      }
    }
    
    while (true) {
      int nbBytes = in.read(b, off, len);
      
      if (nbBytes > 0) {
        return nbBytes;
      }
      else {
        in.close();
        
        if (it.hasNext()) {
          in = it.next();
        }
        else {
          return 0;
        }
      }
    }
  }

  @Override
  public int read() throws IOException {
    if (in == null) {
      if (it.hasNext()) {
        in = it.next();
      }
      else {
        return -1;
      }
    }
    
    while (true) {
      int value = in.read();

      if (value != -1) {
        return value;
      }
      else {
        in.close();
        
        if (it.hasNext()) {
          in = it.next();
        }
        else {
          return -1;
        }
      }
    }
  }

  @Override
  public void close() throws IOException {
    if (in == null) {
      if (it.hasNext()) {
        in = it.next();
      }
      else {
        return;
      }
    }
    
    while (it.hasNext()) {
      in = it.next();
      in.close();
    }
  }
  
}




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