uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

InternationalDB.java (1150B)


      1 import java.io.BufferedInputStream;
      2 import java.io.FileOutputStream;
      3 import java.io.IOException;
      4 import java.io.InputStream;
      5 import java.net.URL;
      6 import java.nio.file.Files;
      7 import java.nio.file.Paths;
      8 import java.nio.file.StandardCopyOption;
      9 
     10 public class InternationalDB {
     11     public String sourceUrl = "https://opensky-network.org/api/states/all?lamin=30.038&lomin=-125.974&lamax=52.214&lomax=-68.748";
     12 
     13     public String locPath = "InternationalFlightTracking.db";
     14 
     15     public int sizeLimit = 2; // limit file size in KB
     16 
     17     public void downloadData() throws IOException {
     18         try (BufferedInputStream inputStream = new BufferedInputStream(new URL(sourceUrl).openStream());
     19              FileOutputStream fileOS = new FileOutputStream(locPath)) {
     20             byte[] data = new byte[1024];
     21             int byteContent;
     22 
     23 
     24             int size = 0;
     25             while (((byteContent = inputStream.read(data, 0, 1024)) != -1 ) && size < sizeLimit) {
     26                 fileOS.write(data, 0, byteContent);
     27                 size++;
     28             }
     29         } catch (IOException e) {
     30             System.out.println("No file permissions");
     31         }
     32     }
     33 }