Patch to add inputStream/outputStream methods to File
Thomas Leonard <tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]>
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Organization | IT Innovation |
| Message-ID | <[email protected]> |
This patch adds inputStream and outputStream sugar methods to File. These are the equivalents of File.textWriter and File.textReader. This means that it is now possible to append binary data to a file in E, and it is also now possible to get an InputStream for a ReadOnlyFile. Thanks, -- Dr Thomas Leonard IT Innovation Centre 2 Venture Road Southampton Hampshire SO16 7NP Tel: +44 0 23 8076 0834 Fax: +44 0 23 8076 0833 mailto:tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected] http://www.it-innovation.soton.ac.uk _______________________________________________ e-lang mailing list [email protected] http://www.eros-os.org/mailman/listinfo/e-lang
0001-Added-inputStream-and-outputStream-sugar-methods.patch
(text/x-patch, 2.7 KB)
>From 60a905c85675969994968a7a3d45a392d17741ff Mon Sep 17 00:00:00 2001 From: Thomas Leonard <tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]> Date: Wed, 2 Dec 2009 11:13:59 +0000 Subject: [PATCH] Added inputStream and outputStream sugar methods to File These are the equivalents of file.textWriter and file.textReader. This means that it is now possible to append binary data to a file in E, and it is also now possible to get an InputStream for a ReadOnlyFile. Patch provided by the University of Southampton IT Innovation Centre. --- src/jsrc/org/erights/e/meta/java/io/FileSugar.java | 17 +++++++++++++++++ .../org/erights/e/meta/java/io/ReadOnlyFile.java | 8 ++++++++ 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/src/jsrc/org/erights/e/meta/java/io/FileSugar.java b/src/jsrc/org/erights/e/meta/java/io/FileSugar.java index 4b06f42..e858a6d 100644 --- a/src/jsrc/org/erights/e/meta/java/io/FileSugar.java +++ b/src/jsrc/org/erights/e/meta/java/io/FileSugar.java @@ -148,6 +148,15 @@ public class FileSugar { } /** + * Open 'self' for reading data. + */ + static public InputStream inputStream(File self) + throws FileNotFoundException { + return new FileInputStream(self); + } + + + /** * Open 'self' for reading text, decoding UTF-8 and turning platform * newlines into '\n's */ @@ -336,6 +345,14 @@ public class FileSugar { } /** + * Open 'self' for appending data. + */ + static public OutputStream outputStream(File self, boolean append) + throws IOException { + return new FileOutputStream(self.getPath(), append); + } + + /** * Write the file (or append to the file) so that its contents represents * the string 'text', turning '\n's into platform newlines, and converting * to UTF-8 diff --git a/src/jsrc/org/erights/e/meta/java/io/ReadOnlyFile.java b/src/jsrc/org/erights/e/meta/java/io/ReadOnlyFile.java index e36e9c3..cc57d54 100644 --- a/src/jsrc/org/erights/e/meta/java/io/ReadOnlyFile.java +++ b/src/jsrc/org/erights/e/meta/java/io/ReadOnlyFile.java @@ -16,6 +16,7 @@ import org.erights.e.elib.tables.Twine; import org.erights.e.elib.util.OneArgFunc; import java.io.BufferedReader; +import java.io.InputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FilenameFilter; @@ -279,6 +280,13 @@ public class ReadOnlyFile extends BaseLoader } /** + * Open 'self' for reading data. + */ + public InputStream inputStream() throws FileNotFoundException { + return FileSugar.inputStream(myPrecious); + } + + /** * @param uriBody */ public Object get(String uriBody) { -- 1.6.3.3