From 1bb7b324422cd208261ab7b7bda7d657ffd6caba Mon Sep 17 00:00:00 2001 From: Kevin Glynn Date: Wed, 6 Apr 2011 16:30:12 +0200 Subject: [PATCH] Support FileStreams --- .../NetFramework/System/IO/StreamWriter.xml | 20 ++++- .../NetFramework/System/IO/TextWriter.xml | 8 +- .../CS2JNet/System/IO/FileStreamSupport.java | 74 ++++++++++++++++++- 3 files changed, 92 insertions(+), 10 deletions(-) diff --git a/CS2JLibrary/NetFramework/System/IO/StreamWriter.xml b/CS2JLibrary/NetFramework/System/IO/StreamWriter.xml index 9cc38b5..c099e03 100644 --- a/CS2JLibrary/NetFramework/System/IO/StreamWriter.xml +++ b/CS2JLibrary/NetFramework/System/IO/StreamWriter.xml @@ -1,4 +1,4 @@ - + - java.io.* + java.io.BufferedWriter BufferedWriter System.IO.StreamWriter @@ -24,7 +24,7 @@ - java.io.* + java.io.BufferedWriter new BufferedWriter(new FileWriter(${path})) @@ -36,7 +36,7 @@ - java.io.* + java.io.BufferedWriter new BufferedWriter(new FileWriter(${path},${append})) @@ -50,6 +50,18 @@ + + + java.io.OutputStreamWriter + + new OutputStreamWriter(${stream}.getOutputStream()) + + + System.IO.FileStream + stream + + + diff --git a/CS2JLibrary/NetFramework/System/IO/TextWriter.xml b/CS2JLibrary/NetFramework/System/IO/TextWriter.xml index afb795e..3bad06a 100644 --- a/CS2JLibrary/NetFramework/System/IO/TextWriter.xml +++ b/CS2JLibrary/NetFramework/System/IO/TextWriter.xml @@ -1,4 +1,4 @@ - + - - TextWriter + + java.io.Writer + + Writer System.IO.TextWriter diff --git a/CS2JLibrary/src/CS2JNet/System/IO/FileStreamSupport.java b/CS2JLibrary/src/CS2JNet/System/IO/FileStreamSupport.java index dfc27ad..7c8136a 100755 --- a/CS2JLibrary/src/CS2JNet/System/IO/FileStreamSupport.java +++ b/CS2JLibrary/src/CS2JNet/System/IO/FileStreamSupport.java @@ -20,9 +20,77 @@ */ package CS2JNet.System.IO; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; + +import CS2JNet.JavaSupport.CS2JRunTimeException; - +/** + * + * @author kevin.glynn@twiglet.com + * + */ public class FileStreamSupport { - - + + + private FileInputStream inputStream = null; + private FileOutputStream outputStream = null; + + /*** + * Initializes a new instance of the FileStreamSupport class with the specified path, + * creation mode, and read/write permission + * + * This class mimics System.IO.FileStream + * + * If mode is read only then set readStream, if write only then set writeStream, + * if readWrite throw an exception :( + * @param path + * @param mode + * @param access + * @throws FileNotFoundException + * @throws CS2JRunTimeException + */ + public FileStreamSupport(String path, FileMode mode, FileAccess access) throws FileNotFoundException, CS2JRunTimeException { + switch (access) { + case Read: + setInputStream(new FileInputStream(path)); + break; + case Write: + setOutputStream(new FileOutputStream(path, mode == FileMode.Append)); + break; + case ReadWrite: + default: + throw new CS2JRunTimeException("CS2J: Read / Write FileStreams are not yet supported"); + } + } + + /** + * @param inputStream the inputStream to set + */ + public void setInputStream(FileInputStream inputStream) { + this.inputStream = inputStream; + } + + /** + * @return the inputStream + */ + public FileInputStream getInputStream() { + return inputStream; + } + + /** + * @param outputStream the outputStream to set + */ + public void setOutputStream(FileOutputStream outputStream) { + this.outputStream = outputStream; + } + + /** + * @return the outputStream + */ + public FileOutputStream getOutputStream() { + return outputStream; + } }