diff --git a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/AbstractResourceSource.java b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/AbstractResourceSource.java deleted file mode 100644 index 9fdfeeac9..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/AbstractResourceSource.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.avaje.ebeaninternal.server.lib.resource; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringWriter; - -public abstract class AbstractResourceSource { - - - /** - * Helper method to read String content. - */ - public String readString(ResourceContent content, int bufSize) throws IOException { - - if (content == null) { - throw new NullPointerException("content is null?"); - } - StringWriter writer = new StringWriter(); - - InputStream is = content.getInputStream(); - InputStreamReader reader = new InputStreamReader(is); - - char[] buf = new char[bufSize]; - int len; - while ((len = reader.read(buf, 0, buf.length)) != -1) { - writer.write(buf, 0, len); - } - - reader.close(); - - return writer.toString(); - } - - /** - * Helper method to read byte[] content. - */ - public byte[] readBytes(ResourceContent content, int bufSize) throws IOException { - - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - - InputStream is = content.getInputStream(); - - byte[] buf = new byte[bufSize]; - int len; - while ((len = is.read(buf, 0, buf.length)) != -1) { - bytes.write(buf, 0, len); - } - - is.close(); - - return bytes.toByteArray(); - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/FileResourceContent.java b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/FileResourceContent.java index e8ab83aeb..b2f6cb07e 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/FileResourceContent.java +++ b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/FileResourceContent.java @@ -11,60 +11,60 @@ import java.util.Date; */ public class FileResourceContent implements ResourceContent { - /** - * The underlying file. - */ - final File file; + /** + * The underlying file. + */ + final File file; final String entryName; - /** - * Create with a File and the entryName. - */ - public FileResourceContent(File file, String entryName) { - this.file = file; - this.entryName = entryName; - } + /** + * Create with a File and the entryName. + */ + public FileResourceContent(File file, String entryName) { + this.file = file; + this.entryName = entryName; + } - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("[").append(getName()); - sb.append("] size[").append(size()); - sb.append("] lastModified[").append(new Date(lastModified())); - sb.append("]"); - return sb.toString(); - } + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("[").append(getName()); + sb.append("] size[").append(size()); + sb.append("] lastModified[").append(new Date(lastModified())); + sb.append("]"); + return sb.toString(); + } - /** - * Returns the entry name which contains the path from the base directory. - *

- * This does not return the full path of the file, but the path relative to - * the FileIoSource directory. - *

- */ - public String getName() { - return entryName; - } + /** + * Returns the entry name which contains the path from the base directory. + *

+ * This does not return the full path of the file, but the path relative to + * the FileIoSource directory. + *

+ */ + public String getName() { + return entryName; + } - /** - * Return the time the file was last modified. - */ - public long lastModified() { - return file.lastModified(); - } + /** + * Return the time the file was last modified. + */ + public long lastModified() { + return file.lastModified(); + } - /** - * Return the size of the file. - */ - public long size() { - return file.length(); - } + /** + * Return the size of the file. + */ + public long size() { + return file.length(); + } - /** - * Return the input stream for this file. - */ - public InputStream getInputStream() throws IOException { + /** + * Return the input stream for this file. + */ + public InputStream getInputStream() throws IOException { - return new FileInputStream(file); - } + return new FileInputStream(file); + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/FileResourceSource.java b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/FileResourceSource.java index 1d65aef1d..496660c1e 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/FileResourceSource.java +++ b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/FileResourceSource.java @@ -5,46 +5,46 @@ import java.io.File; /** * A file system directory represented as a FileSource. */ -public class FileResourceSource extends AbstractResourceSource implements ResourceSource { +public class FileResourceSource implements ResourceSource { - /** - * The directory name. - */ - final String directory; + /** + * The directory name. + */ + final String directory; final String baseDir; - - /** - * Create the source based on a directory name. - */ - public FileResourceSource(String directory){ - this.directory = directory; - this.baseDir = directory+File.separator; - } - - /** - * Create the source based on a directory file. - */ - public FileResourceSource(File dir){ - this(dir.getPath()); - } - - - public String getRealPath() { - return directory; - } - /** - * Search for the given file and return as IoContent. - */ - public ResourceContent getContent(String entry) { - - String fullPath = baseDir+entry; - - File f = new File(fullPath); - if (f.exists()){ - return new FileResourceContent(f, entry); - } - return null; + /** + * Create the source based on a directory name. + */ + public FileResourceSource(String directory) { + this.directory = directory; + this.baseDir = directory + File.separator; + } + + /** + * Create the source based on a directory file. + */ + public FileResourceSource(File dir) { + this(dir.getPath()); + } + + + public String getRealPath() { + return directory; + } + + /** + * Search for the given file and return as IoContent. + */ + public ResourceContent getContent(String entry) { + + String fullPath = baseDir + entry; + + File f = new File(fullPath); + if (f.exists()) { + return new FileResourceContent(f, entry); } + return null; + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/ResourceContent.java b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/ResourceContent.java index c0db9cf7a..6aab953c7 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/ResourceContent.java +++ b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/ResourceContent.java @@ -11,24 +11,24 @@ import java.io.InputStream; */ public interface ResourceContent { - /** - * The name of the content. - */ - String getName(); + /** + * The name of the content. + */ + String getName(); - /** - * The size of the content in bytes. - */ - long size(); + /** + * The size of the content in bytes. + */ + long size(); - /** - * The last modified timestamp of the content. - */ - long lastModified(); + /** + * The last modified timestamp of the content. + */ + long lastModified(); - /** - * The content itself. - */ - InputStream getInputStream() throws IOException; + /** + * The content itself. + */ + InputStream getInputStream() throws IOException; } diff --git a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/ResourceSource.java b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/ResourceSource.java index fc5be7cdf..1be9338bb 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/ResourceSource.java +++ b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/ResourceSource.java @@ -1,7 +1,5 @@ package com.avaje.ebeaninternal.server.lib.resource; -import java.io.IOException; - /** * A Source for ResourceManager. *

@@ -25,13 +23,4 @@ public interface ResourceSource { */ ResourceContent getContent(String entry); - /** - * Return the content as a String. - */ - String readString(ResourceContent content, int bufSize) throws IOException; - - /** - * Return the content as a byte[]. - */ - byte[] readBytes(ResourceContent content, int bufSize) throws IOException; } diff --git a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/UrlResourceContent.java b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/UrlResourceContent.java deleted file mode 100644 index f3fedf88a..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/UrlResourceContent.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.avaje.ebeaninternal.server.lib.resource; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.util.Date; - -/** - * Content from a URL Resource. - */ -public class UrlResourceContent implements ResourceContent { - - final String entryName; - - URLConnection con; - - /** - * Create with a File and the entryName. - */ - public UrlResourceContent(URL url, String entryName) { - //this.url = url; - this.entryName = entryName; - try { - con = url.openConnection(); - } catch (IOException ex){ - throw new RuntimeException(ex); - } - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("[").append(getName()); - sb.append("] size[").append(size()); - sb.append("] lastModified[").append(new Date(lastModified())); - sb.append("]"); - return sb.toString(); - } - - /** - * Returns the entry name which contains the path from the base directory. - *

- * This does not return the full path of the file, but the path relative to - * the FileIoSource directory. - *

- */ - public String getName() { - return entryName; - } - - /** - * Return the time the file was last modified. - */ - public long lastModified() { - return con.getLastModified(); - } - - /** - * Return the size of the file. - */ - public long size() { - return con.getContentLength(); - } - - /** - * Return the input stream for this file. - */ - public InputStream getInputStream() throws IOException { - - return con.getInputStream(); - } -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/UrlResourceSource.java b/src/main/java/com/avaje/ebeaninternal/server/lib/resource/UrlResourceSource.java deleted file mode 100644 index 6a60938c6..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/lib/resource/UrlResourceSource.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.avaje.ebeaninternal.server.lib.resource; - -import java.net.MalformedURLException; -import java.net.URL; - -import javax.servlet.ServletContext; - -import com.avaje.ebeaninternal.server.lib.util.GeneralException; - -/** - * A file system directory represented as a FileSource. - */ -public class UrlResourceSource extends AbstractResourceSource implements ResourceSource { - - - ServletContext sc; - - String basePath; - - String realPath; - - /** - * Create the source based on a directory name. - */ - public UrlResourceSource(ServletContext sc, String basePath){ - this.sc = sc; - if (basePath == null){ - this.basePath = "/"; - } else { - this.basePath = "/"+basePath+"/"; - } - this.realPath = sc.getRealPath(basePath); - } - - /** - * Returns the "real path" from the ServletContext root. - *

- * This can be null for unpacked WAR deployment. - *

- */ - public String getRealPath() { - return realPath; - } - - /** - * Search for the given URL resource and return as ResourceContent. - *

- * Returns null if the resource is not found. - *

- */ - public ResourceContent getContent(String entry) { - - try { - URL url = sc.getResource(basePath+entry); - if (url != null){ - return new UrlResourceContent(url, entry); - } - return null; - - } catch (MalformedURLException ex){ - throw new GeneralException(ex); - } - } -}