package org.musetest.core.resource.origin;

import org.musetest.core.resource.*;

import java.io.*;

/**
 * @author Christopher L Merrill (see LICENSE.txt for license details)
 */
public class FileResourceOrigin implements ResourceOrigin
    {
    public FileResourceOrigin(File source)
        {
        super();
        _file = source;
        }

    @Override
    public String getDescription()
        {
        return "File: " + _file.getAbsolutePath();
        }

    @Override
    public String suggestId()
        {
        String name = _file.getName();
        if (name.contains("."))
            name = name.substring(0, name.indexOf("."));
        return name;
        }

    @Override
    public InputStream asInputStream() throws IOException
        {
        return new FileInputStream(_file);
        }

    @Override
    public OutputStream asOutputStream() throws IOException
        {
        return new FileOutputStream(_file);
        }

    public File getFile()
        {
        return _file;
        }

    @Override
    public ResourceSerializer getSerializer()
        {
        return _serializer;
        }

    @Override
    public void setSerializer(ResourceSerializer serializer)
        {
        _serializer = serializer;
        }

    private final File _file;
    private ResourceSerializer _serializer;
    }



@@ -1013,32 +1013,120 @@
 ile;%0A        %7D%0A%0A
+    @Override%0A    public String toString()%0A%09    %7B%0A%09    return getDescription();%0A%09    %7D%0A%0A
     @Override%0A  
@@ -1431,7 +1431,4 @@
    %7D
-%0A%0A%0A

implement toString()