package org.bricolages.streaming;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Paths;

import lombok.*;

public class LocalFileSourceLocator implements SourceLocator {
    private final String fileUrl;

    LocalFileSourceLocator(String filepath) throws IOException {
        // /path/to/file -> file:/path/to/file
        // ./relative/file -> file:/path/to/relative/file
        this.fileUrl = new File(filepath).getCanonicalFile().toURI().toString();
    }

    public BufferedReader open() throws IOException {
        val filereader = new FileReader(fileUrl);
		return new BufferedReader(filereader);
    }

    public String toString() {
        return this.fileUrl;
    }
}

@@ -80,16 +80,48 @@
 o.File;%0A
+import java.io.FileInputStream;%0A
 import j
@@ -183,22 +183,138 @@
 ava.
-nio.file.Paths
+io.InputStreamReader;%0Aimport java.io.Reader;%0Aimport java.net.URI;%0Aimport java.nio.file.Paths;%0Aimport java.util.zip.GZIPInputStream
 ;%0A%0Ai
@@ -411,22 +411,19 @@
 e final 
-String
+URI
  fileUrl
@@ -667,19 +667,8 @@
 RI()
-.toString()
 ;%0A  
@@ -742,84 +742,370 @@
 val 
-filereader = new FileReader(fileUrl);%0A%09%09return new BufferedReader(filereader
+inputStream = new FileInputStream(fileUrl.getPath());%0A        if (isGzip()) %7B%0A            return new BufferedReader(new InputStreamReader(new GZIPInputStream(inputStream)));%0A        %7D else %7B%0A            return new BufferedReader(new InputStreamReader(inputStream));%0A        %7D%0A    %7D%0A%0A    private boolean isGzip() %7B%0A        return fileUrl.toString().endsWith(%22.gz%22
 );%0A 
@@ -1168,16 +1168,27 @@
 .fileUrl
+.toString()
 ;%0A    %7D%0A

Support gzipped local file