Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
834ae01
commit 2c186ab
Showing
3 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// A few examples of reading a file. | ||
|
||
import io | ||
|
||
create("example/out.magc") use with | ||
it writeByte(0) | ||
it writeByte(128) | ||
it writeByte(255) | ||
it writeInt(1234567) | ||
end | ||
|
||
print("Done") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.stuffwithstuff.magpie.util; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
public class FileWriter { | ||
public FileWriter(String path) throws IOException { | ||
mStream = new DataOutputStream(new FileOutputStream(path)); | ||
} | ||
|
||
public boolean isOpen() { | ||
return mStream != null; | ||
} | ||
|
||
public void close() { | ||
// Do nothing if already closed. | ||
if (mStream == null) return; | ||
|
||
try { | ||
mStream.close(); | ||
mStream = null; | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void writeByte(int value) throws IOException { | ||
mStream.writeByte(value); | ||
} | ||
|
||
public void writeInt(int value) throws IOException { | ||
mStream.writeInt(value); | ||
} | ||
|
||
private DataOutputStream mStream; | ||
} |