|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.tridas.io.util.FileHelper
public class FileHelper
Helps working with most files.
Field Summary | |
---|---|
String |
envPath
|
Constructor Summary | |
---|---|
FileHelper()
|
|
FileHelper(String argRootDataPath)
|
Method Summary | |
---|---|
File |
createFile(String where)
|
InputStream |
createInput(String filename)
Simplified method to open a Java InputStream. |
InputStream |
createInputRaw(String filename)
Call createInput() without automatic gzip decompression. |
OutputStream |
createOutput(String filename)
Similar to createInput(), this creates a Java OutputStream for a given filename or path. |
BufferedReader |
createReader(String filename)
I want to read lines from a file. |
PrintWriter |
createWriter(String filename)
I want to print lines to a file. |
String |
fullPath(String where)
Prepend the Environment path to the filename (or path) that is passed in. |
File |
inputFile()
|
static Boolean |
isBinary(String[] argLines)
Determine whether a file contains non-printable characters, suggesting that its a binary file. |
byte[] |
loadBytes(String filename)
|
String[] |
loadStrings(String filename)
Load data from a file and shove it into a String array. |
String[] |
loadStrings(String filename,
String argEncoding)
|
String[] |
loadStringsFromDetectedCharset(String argFilename)
|
File |
outputFile()
|
void |
saveBytes(String filename,
byte[] buffer)
Saves bytes to a file to the Environment path. |
File |
saveFile(String where)
Identical to savePath(), but returns a File object. |
String |
savePath(String where)
Returns a path inside the applet folder to save to. |
void |
saveStream(File targetFile,
String sourceLocation)
Identical to the other saveStream(), but writes to a File object, for greater control over the file location. |
void |
saveStream(String targetFilename,
String sourceLocation)
Save the contents of a stream to a file usually where the jar is located, but can be customized with the FileHelper(String) constructor. |
void |
saveStrings(String filename,
String[] strings)
|
void |
saveStrings(String filename,
String[] strings,
String argEncoding)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final String envPath
Constructor Detail |
---|
public FileHelper()
public FileHelper(String argRootDataPath)
Method Detail |
---|
public File outputFile()
public File inputFile()
public PrintWriter createWriter(String filename)
public BufferedReader createReader(String filename)
public String[] loadStringsFromDetectedCharset(String argFilename)
public String[] loadStrings(String filename)
Exceptions are handled internally, when an error, occurs, an exception is printed to the console and 'null' is returned, but the program continues running. This is a tradeoff between 1) showing the user that there was a problem but 2) not requiring that all i/o code is contained in try/catch blocks, for the sake of new users (or people who are just trying to get things done in a "scripting" fashion). If you want to handle exceptions, use Java methods for I/O.
public String[] loadStrings(String filename, String argEncoding) throws UnsupportedEncodingException
UnsupportedEncodingException
public byte[] loadBytes(String filename)
public InputStream createInputRaw(String filename)
public InputStream createInput(String filename)
This method is useful if you want to use the facilities provided by PApplet to easily open things from the data folder or from a URL, but want an InputStream object so that you can use other Java methods to take more control of how the stream is read.
If the requested item doesn't exist, null is returned
If not online, this will also check to see if the user is asking for a file whose name isn't properly capitalized. This helps prevent issues when a sketch is exported to the web, where case sensitivity matters, as opposed to Windows and the Mac OS default where case sensitivity is preserved but ignored.
It is strongly recommended that libraries use this method to open data files, so that the loading sequence is handled in the same way as functions like loadBytes(), loadImage(), etc.
The filename passed in can be:
public void saveStrings(String filename, String[] strings)
public void saveStrings(String filename, String[] strings, String argEncoding) throws UnsupportedEncodingException
UnsupportedEncodingException
public void saveBytes(String filename, byte[] buffer)
FileHelper(String)
constructor. The filename
can be a
relative path, i.e. "hey/more/directories/wowbytes.txt" would save the "hey"
directory in the Environment path.
public void saveStream(File targetFile, String sourceLocation)
public void saveStream(String targetFilename, String sourceLocation)
FileHelper(String)
constructor. This is
basically saveBytes(blah, loadBytes()), but done in a less confusing
manner.
public OutputStream createOutput(String filename)
FileHelper(String)
.
If the path does not exist, intermediate folders will be created. If an exception
occurs, it will be printed to the console, and null will be returned.
public String fullPath(String where)
public File createFile(String where)
public String savePath(String where)
public File saveFile(String where)
public static Boolean isBinary(String[] argLines)
argLines
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |