package de.christianscheb.partyprojector.model;

import de.christianscheb.partyprojector.view.PictureProviderInterface;
import javafx.scene.image.Image;

import java.io.InputStream;
import java.util.ArrayDeque;

public class PictureStorage implements PictureProviderInterface {

    private ArrayDeque<Image> pictures = new ArrayDeque<>();

    public void addImage(InputStream stream) {
        pictures.push(new Image(stream));
    }

    @Override
    public Image getPicture() {
        if (pictures.size() > 0) {
            return pictures.removeFirst();
        }

        return null;
    }
}

@@ -162,27 +162,119 @@
 java.io.
-InputStream
+*;%0Aimport java.net.MalformedURLException;%0Aimport java.nio.file.Files;%0Aimport java.text.SimpleDateFormat
 ;%0Aimport
@@ -295,16 +295,43 @@
 ayDeque;
+%0Aimport java.util.Calendar;
 %0A%0Apublic
@@ -391,16 +391,51 @@
 face %7B%0A%0A
+    private final File pictureDir;%0A
     priv
@@ -503,83 +503,999 @@
 lic 
-void addImage(InputStream stream) %7B%0A        pictures.push(new Image(stream)
+PictureStorage() %7B%0A        pictureDir = new File(System.getProperty(%22user.dir%22) + %22/pictures%22);%0A        if (!pictureDir.exists()) %7B%0A            pictureDir.mkdirs();%0A        %7D%0A    %7D%0A%0A    public void addImage(InputStream stream) %7B%0A        // Store image on disk%0A        String timeStamp = new SimpleDateFormat(%22yyyy-MM-dd_HH-mm-ss%22).format(Calendar.getInstance().getTime());%0A        File pictureFile = new File(pictureDir, timeStamp + %22.jpg%22);%0A        try %7B%0A            Files.copy(stream, pictureFile.toPath());%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A            return;%0A        %7D%0A%0A        // Push to queue%0A        Image image;%0A        try %7B%0A            image = new Image(pictureFile.toURI().toURL().toString());%0A        %7D catch (MalformedURLException e) %7B%0A            e.printStackTrace();%0A            return;%0A        %7D%0A%0A        if (image.isError()) %7B%0A            System.err.println(%22Could not read image%22);%0A            return;%0A        %7D%0A        pictures.push(image
 );%0A 

Store pictures on disk