// Path: src/main/java/org/fbk/cit/hlt/parsers/hls/Segment.java
// public class Segment implements Downloadable {
//     private float duration;
//     private String title;
//     private String uri;
//     private Encryption encryption;
//     private int sequence;
//     private int discontinuity;
// 
//     public Segment(float duration, String title, String uri) {
//         this(duration, title, uri, 0);
//     }
// 
//     public Segment(float duration, String title, String uri, int sequence) {
//         this.duration = duration;
//         this.title = title;
//         this.uri = uri;
//         this.encryption = null;
//         this.sequence = sequence;
//     }
// 
//     public float getDuration() {
//         return duration;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getUri() {
//         return uri;
//     }
// 
//     public Encryption getEncryption() {
//         return encryption;
//     }
// 
//     public int getSequence() {
//         return sequence;
//     }
// 
//     public void setEncryption(Encryption encryption) {
//         this.encryption = encryption;
//     }
// 
//     public int getDiscontinuity() {
//         return discontinuity;
//     }
// 
//     public void setDiscontinuity(int discontinuity) {
//         this.discontinuity = discontinuity;
//     }
// 
//     public void setUri(String uri) {
//         this.uri = uri;
//     }
// }


import org.apache.commons.io.IOUtils;
import org.fbk.cit.hlt.parsers.hls.Segment;
import java.io.*;
import java.nio.file.FileSystemException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
        }
        
        //Creating subdirectories
        playlists = new File(getChildPath(folder.toString(), "playlists"));
        segments = new File(getChildPath(folder.toString(), "segments"));
        if ((!playlists.exists() && !playlists.mkdir()) || (!segments.exists() && !segments.mkdir())) {
            throw new FileSystemException("Can't create subdirectories");
        }
        if (!playlists.isDirectory() || !segments.isDirectory()) {
            throw new FileSystemException("Sanity check #1 failed");
        }
    }
    
    @Override
    public void savePlaylist(String type, byte[] data) throws IOException {
        String name = type+"-"+(new SimpleDateFormat("yyyy.MM.dd-HH-mm-ss").format(new Date()))+".m3u8";
        saveFile(playlists, name, data);
    }

    @Override
    public void saveSegment(int sequence, byte[] data) throws IOException {
        String name = sequence+".ts";
        saveFile(segments, name, data);
    }

    @Override
    public void serializeSegmentInfo(Collection<Segment> segments) throws IOException {
        if (infoWriter == null) {
            startWritingInfo();
        }
// Path: src/main/java/org/fbk/cit/hlt/parsers/hls/Segment.java
// public class Segment implements Downloadable {
//     private float duration;
//     private String title;
//     private String uri;
//     private Encryption encryption;
//     private int sequence;
//     private int discontinuity;
// 
//     public Segment(float duration, String title, String uri) {
//         this(duration, title, uri, 0);
//     }
// 
//     public Segment(float duration, String title, String uri, int sequence) {
//         this.duration = duration;
//         this.title = title;
//         this.uri = uri;
//         this.encryption = null;
//         this.sequence = sequence;
//     }
// 
//     public float getDuration() {
//         return duration;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getUri() {
//         return uri;
//     }
// 
//     public Encryption getEncryption() {
//         return encryption;
//     }
// 
//     public int getSequence() {
//         return sequence;
//     }
// 
//     public void setEncryption(Encryption encryption) {
//         this.encryption = encryption;
//     }
// 
//     public int getDiscontinuity() {
//         return discontinuity;
//     }
// 
//     public void setDiscontinuity(int discontinuity) {
//         this.discontinuity = discontinuity;
//     }
// 
//     public void setUri(String uri) {
//         this.uri = uri;
//     }
// }


// Path: src/main/java/org/fbk/cit/hlt/parsers/hls/persist/FilePersister.java
import org.apache.commons.io.IOUtils;
import org.fbk.cit.hlt.parsers.hls.Segment;
import java.io.*;
import java.nio.file.FileSystemException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;

        }
        
        //Creating subdirectories
        playlists = new File(getChildPath(folder.toString(), "playlists"));
        segments = new File(getChildPath(folder.toString(), "segments"));
        if ((!playlists.exists() && !playlists.mkdir()) || (!segments.exists() && !segments.mkdir())) {
            throw new FileSystemException("Can't create subdirectories");
        }
        if (!playlists.isDirectory() || !segments.isDirectory()) {
            throw new FileSystemException("Sanity check #1 failed");
        }
    }
    
    @Override
    public void savePlaylist(String type, byte[] data) throws IOException {
        String name = type+"-"+(new SimpleDateFormat("yyyy.MM.dd-HH-mm-ss").format(new Date()))+".m3u8";
        saveFile(playlists, name, data);
    }

    @Override
    public void saveSegment(int sequence, byte[] data) throws IOException {
        String name = sequence+".ts";
        saveFile(segments, name, data);
    }

    @Override
    public void serializeSegmentInfo(Collection<Segment> segments) throws IOException {
        if (infoWriter == null) {
            startWritingInfo();
        }
        for (Segment segment : segments) {