package org.aktin.broker;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.aktin.broker.server.DateDataSource;


public class PathDataSource implements DateDataSource {
	private static final Logger log = Logger.getLogger(PathDataSource.class.getName());

	private Path path;
	private String type;
	private Instant lastModified;

	public PathDataSource(Path path, String type, Instant lastModified){
		this.path = path;
		this.type = type;
		this.lastModified = lastModified;
	}
	@Override
	public String getContentType() {
		return type;
	}

	@Override
	public InputStream getInputStream() throws IOException {
		return Files.newInputStream(path);
	}

	@Override
	public String getName() {
		return path.getFileName().toString();
	}

	@Override
	public OutputStream getOutputStream() throws IOException {
		return Files.newOutputStream(path);
	}
	@Override
	public Instant getLastModified() {
		return lastModified;
	}
	@Override
	public Long getContentLength() {
		try {
			return Files.size(path);
		} catch (IOException e) {
			log.log(Level.WARNING, "Unable to determine file size", e);
			return null;
		}
	}

}

@@ -726,24 +726,134 @@
 n type;%0A%09%7D%0A%0A
+%09@Override%0A%09public String toString() %7B%0A%09%09return %22PathDataSource(path=%22+path.toString()+%22, type=%22+type+%22)%22;%0A%09%7D%0A
 %09@Override%0A%09
@@ -1413,10 +1413,53 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09public Path getPath() %7B%0A%09%09return path;%0A%09%7D%0A
 %7D%0A

allow access to path, tostring method