mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
Support FileStreams
This commit is contained in:
parent
aa8cf2f8c0
commit
1bb7b32442
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -9,7 +9,7 @@
|
||||
-->
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports>
|
||||
<Import>java.io.*</Import>
|
||||
<Import>java.io.BufferedWriter</Import>
|
||||
</Imports>
|
||||
<Java>BufferedWriter</Java>
|
||||
<Name>System.IO.StreamWriter</Name>
|
||||
@ -24,7 +24,7 @@
|
||||
<Constructors>
|
||||
<Constructor>
|
||||
<Imports>
|
||||
<Import>java.io.*</Import>
|
||||
<Import>java.io.BufferedWriter</Import>
|
||||
</Imports>
|
||||
<Java>new BufferedWriter(new FileWriter(${path}))</Java>
|
||||
<Params>
|
||||
@ -36,7 +36,7 @@
|
||||
</Constructor>
|
||||
<Constructor>
|
||||
<Imports>
|
||||
<Import>java.io.*</Import>
|
||||
<Import>java.io.BufferedWriter</Import>
|
||||
</Imports>
|
||||
<Java>new BufferedWriter(new FileWriter(${path},${append}))</Java>
|
||||
<Params>
|
||||
@ -50,6 +50,18 @@
|
||||
</Param>
|
||||
</Params>
|
||||
</Constructor>
|
||||
<Constructor>
|
||||
<Imports>
|
||||
<Import>java.io.OutputStreamWriter</Import>
|
||||
</Imports>
|
||||
<Java>new OutputStreamWriter(${stream}.getOutputStream())</Java>
|
||||
<Params>
|
||||
<Param>
|
||||
<Type>System.IO.FileStream</Type>
|
||||
<Name>stream</Name>
|
||||
</Param>
|
||||
</Params>
|
||||
</Constructor>
|
||||
</Constructors>
|
||||
<Fields />
|
||||
<Casts />
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -8,8 +8,10 @@
|
||||
|
||||
-->
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>TextWriter</Java>
|
||||
<Imports>
|
||||
<Import>java.io.Writer</Import>
|
||||
</Imports>
|
||||
<Java>Writer</Java>
|
||||
<Name>System.IO.TextWriter</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user