// Path: src/main/java/com/lumata/lib/lupa/ReadableResource.java
// public interface ReadableResource {
// 
// 	URL getUrl();
// 
// 	/**
// 	 * Move the current URL to the redirection path and set the specified url as the actual resource url.
// 	 * 
// 	 * @param url
// 	 *            the redirectionUrl
// 	 */
// 	void makeRedirection(URL url);
// 
// 	Optional<URL[]> getRedirectionPath();
// 
// 	Optional<MediaType> getContentType();
// 
// 	InputStream read() throws IOException;
// 
// 	void discard();
// }
// 
// Path: src/main/java/com/lumata/lib/lupa/TextReadableResource.java
// public interface TextReadableResource extends ReadableResource {
// 
// 	/**
// 	 * Tries to discover the encoding of the resources and use it to consume this resource as text.
// 	 * 
// 	 * @return a {@link Reader}
// 	 */
// 	Reader readAsText() throws IOException;
// 
// 	/**
// 	 * Uses the specified {@link Charset} to consume this resource as text.
// 	 * 
// 	 * @return a {@link Reader}
// 	 */
// 	Reader readAsText(Charset charset) throws IOException;
// 
// }


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
import com.google.common.net.MediaType;
import com.lumata.lib.lupa.ReadableResource;
import com.lumata.lib.lupa.TextReadableResource;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
/**
 * Copyright (c) 2013 Lumata
 * 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 com.lumata.lib.lupa.internal;




/**
 * @author Alexander De Leon - alexander.leon@lumatagroup.com
 * 
 */
public class TextReadableResourceDecorator implements TextReadableResource {

	private static final Logger LOG = LoggerFactory.getLogger(TextReadableResourceDecorator.class);

	private static final int BUFFER_SIZE = 1024;

// Path: src/main/java/com/lumata/lib/lupa/ReadableResource.java
// public interface ReadableResource {
// 
// 	URL getUrl();
// 
// 	/**
// 	 * Move the current URL to the redirection path and set the specified url as the actual resource url.
// 	 * 
// 	 * @param url
// 	 *            the redirectionUrl
// 	 */
// 	void makeRedirection(URL url);
// 
// 	Optional<URL[]> getRedirectionPath();
// 
// 	Optional<MediaType> getContentType();
// 
// 	InputStream read() throws IOException;
// 
// 	void discard();
// }
// 
// Path: src/main/java/com/lumata/lib/lupa/TextReadableResource.java
// public interface TextReadableResource extends ReadableResource {
// 
// 	/**
// 	 * Tries to discover the encoding of the resources and use it to consume this resource as text.
// 	 * 
// 	 * @return a {@link Reader}
// 	 */
// 	Reader readAsText() throws IOException;
// 
// 	/**
// 	 * Uses the specified {@link Charset} to consume this resource as text.
// 	 * 
// 	 * @return a {@link Reader}
// 	 */
// 	Reader readAsText(Charset charset) throws IOException;
// 
// }


// Path: src/main/java/com/lumata/lib/lupa/internal/TextReadableResourceDecorator.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
import com.google.common.net.MediaType;
import com.lumata.lib.lupa.ReadableResource;
import com.lumata.lib.lupa.TextReadableResource;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;

/**
 * Copyright (c) 2013 Lumata
 * 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 com.lumata.lib.lupa.internal;




/**
 * @author Alexander De Leon - alexander.leon@lumatagroup.com
 * 
 */
public class TextReadableResourceDecorator implements TextReadableResource {

	private static final Logger LOG = LoggerFactory.getLogger(TextReadableResourceDecorator.class);

	private static final int BUFFER_SIZE = 1024;

	private final ReadableResource resource;