/*
 * This file is part of SpongeAPI, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.api.asset;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.io.ByteStreams;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * Represents an {@link Asset} within Sponge that belongs to a {@link Plugin}.
 */
public interface Asset {

    /**
     * Returns the original {@link Plugin} owner of this Asset.
     *
     * @return Original owner of asset
     */
    PluginContainer getOwner();

    /**
     * Returns the {@link URL} to this Asset.
     *
     * @return URL to asset
     */
    URL getUrl();

    /**
     * Copies this Asset to the specified 'output' {@link Path}.
     *
     * @param output Path to copy to
     * @throws IOException
     */
    default void copyToFile(Path output) throws IOException {
        checkNotNull(output, "output");
        InputStream in = getUrl().openStream();
        Files.copy(in, output);
        in.close();
    }

    /**
     * Reads this Asset in it's entirety as a {@link String} and returns the
     * result.
     *
     * @return String representation of Asset
     * @throws IOException
     */
    default String readString() throws IOException {
        StringBuilder result = new StringBuilder();
        String ln;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(getUrl().openStream()))) {
            while ((ln = reader.readLine()) != null) {
                result.append(ln).append('\n');
            }
        }
        return result.toString();
    }

    /**
     * Reads this Asset in it's entirety as a byte array and returns the
     * result.
     *
     * @return Byte array representation of Asset
     * @throws IOException
     */
    default byte[] readBytes() throws IOException {
        try (InputStream in = getUrl().openStream()) {
            return ByteStreams.toByteArray(in);
        }
    }

}

@@ -1376,26 +1376,24 @@
 mmon.io.
-ByteStream
+Resource
 s;%0Aimpor
@@ -1489,39 +1489,8 @@
 r;%0A%0A
-import java.io.BufferedReader;%0A
 impo
@@ -1557,49 +1557,90 @@
 ava.
-io.InputStreamReader;%0Aimport java.net.URL
+net.URL;%0Aimport java.nio.charset.Charset;%0Aimport java.nio.charset.StandardCharsets
 ;%0Aim
@@ -1691,16 +1691,39 @@
 le.Path;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -1829,16 +1829,163 @@
 sset %7B%0A%0A
+    /**%0A     * The default %7B@link Charset%7D that is used for reading %7B@link Asset%7Ds.%0A     */%0A    Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;%0A%0A
     /**%0A
@@ -2513,16 +2513,21 @@
         
+try (
 InputStr
@@ -2556,18 +2556,24 @@
 Stream()
-;%0A
+) %7B%0A    
         
@@ -2608,19 +2608,9 @@
     
-in.close();
+%7D
 %0A   
@@ -2866,333 +2866,1148 @@
     
-StringBuilder result = new StringBuilder();%0A        String ln;%0A        try (BufferedReader reader = new BufferedReader(new InputStreamReader(getUrl().openStream()))) %7B
+return readString(DEFAULT_CHARSET);%0A    %7D%0A%0A    /**%0A     * Reads this Asset in it's entirety as a %7B@link String%7D and returns the%0A     * result.%0A     *%0A     * @param charset The charset to read the asset with%0A     * @return String representation of Asset%0A     * @throws IOException%0A     */%0A    default String readString(Charset charset) throws IOException %7B%0A        checkNotNull(charset, %22charset%22);%0A        return Resources.toString(getUrl(), charset);%0A    %7D%0A%0A    /**%0A     * Reads all lines from the asset and returns the result.
 %0A     
+*%0A
      
-  while ((ln = reader.readLine()) != null) %7B
+* @return The lines read from the asset%0A     * @throws IOException%0A     */%0A    default List%3CString%3E readLines() throws IOException %7B%0A        return readLines(DEFAULT_CHARSET);%0A    %7D%0A
 %0A    
+/**%0A
      
-       result.append(ln).append('%5Cn');
+* Reads all lines from the asset and returns the result.%0A     *%0A     * @param charset The charset to read the asset with%0A     * @return An immutable list of the lines read from the asset%0A     * @throws IOException
 %0A     
+*/%0A
     
-   %7D%0A        %7D%0A        return result.toString
+default List%3CString%3E readLines(Charset charset) throws IOException %7B%0A        checkNotNull(charset, %22charset%22);%0A        return Resources.asCharSource(getUrl(), charset).readLines
 ();%0A
@@ -4265,112 +4265,47 @@
     
-try (InputStream in = getUrl().openStream()) %7B%0A            return ByteStreams.toByteArray(in);%0A        %7D
+return Resources.toByteArray(getUrl());
 %0A   

Add Asset.readLines() and fix try-with-resources on copyToFile