Skip to content

Commit

Permalink
[updated] FileHandle, lastModified.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan.sweet committed Oct 26, 2011
1 parent 4b0bd18 commit f7dfcfd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,8 @@ public long length () {
}
return super.length();
}

public long lastModified () {
return super.lastModified();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,29 +245,29 @@ public void postRunnable (Runnable runnable) {

public void log (String tag, String message) {
if (logLevel >= LOG_INFO) {
System.out.println(tag + ":" + message);
System.out.println(tag + ": " + message);
}
}

@Override
public void log (String tag, String message, Exception exception) {
if (logLevel >= LOG_INFO) {
System.out.println(tag + ":" + message);
System.out.println(tag + ": " + message);
exception.printStackTrace(System.out);
}
}

@Override
public void error (String tag, String message) {
if (logLevel >= LOG_ERROR) {
System.err.println(tag + ":" + message);
System.err.println(tag + ": " + message);
}
}

@Override
public void error (String tag, String message, Exception exception) {
if (logLevel >= LOG_ERROR) {
System.err.println(tag + ":" + message);
System.err.println(tag + ": " + message);
exception.printStackTrace(System.err);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,29 +247,29 @@ public void postRunnable (Runnable runnable) {

public void log (String tag, String message) {
if (logLevel >= LOG_INFO) {
System.out.println(tag + ":" + message);
System.out.println(tag + ": " + message);
}
}

@Override
public void log (String tag, String message, Exception exception) {
if (logLevel >= LOG_INFO) {
System.out.println(tag + ":" + message);
System.out.println(tag + ": " + message);
exception.printStackTrace(System.out);
}
}

@Override
public void error (String tag, String message) {
if (logLevel >= LOG_ERROR) {
System.err.println(tag + ":" + message);
System.err.println(tag + ": " + message);
}
}

@Override
public void error (String tag, String message, Exception exception) {
if (logLevel >= LOG_ERROR) {
System.err.println(tag + ":" + message);
System.err.println(tag + ": " + message);
exception.printStackTrace(System.err);
}
}
Expand Down
37 changes: 24 additions & 13 deletions gdx/src/com/badlogic/gdx/files/FileHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public byte[] readBytes () {
return buffer;
}

/** Returns a stream for writing to this file.
/** Returns a stream for writing to this file. Parent directories will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
* {@link FileType#Internal} file, or if it could not be written. */
Expand All @@ -204,7 +204,8 @@ public OutputStream write (boolean append) {
}
}

/** Reads the remaining bytes from the specified stream and writes them to this file. The stream is closed.
/** Reads the remaining bytes from the specified stream and writes them to this file. The stream is closed. Parent directories
* will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
* {@link FileType#Internal} file, or if it could not be written. */
Expand Down Expand Up @@ -233,22 +234,23 @@ public void write (InputStream input, boolean append) {

}

/** Returns a writer for writing to this file using the default charset.
/** Returns a writer for writing to this file using the default charset. Parent directories will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
* {@link FileType#Internal} file, or if it could not be written. */
public Writer writer (boolean append) {
return writer(append, null);
}

/** Returns a writer for writing to this file.
/** Returns a writer for writing to this file. Parent directories will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @param charset May be null to use the default charset.
* @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
* {@link FileType#Internal} file, or if it could not be written. */
public Writer writer (boolean append, String charset) {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot write to a classpath file: " + file);
if (type == FileType.Internal) throw new GdxRuntimeException("Cannot write to an internal file: " + file);
parent().mkdirs();
try {
FileOutputStream output = new FileOutputStream(file(), append);
if (charset == null)
Expand All @@ -262,15 +264,15 @@ public Writer writer (boolean append, String charset) {
}
}

/** Writes the specified string to the file using the default charset.
/** Writes the specified string to the file using the default charset. Parent directories will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
* {@link FileType#Internal} file, or if it could not be written. */
public void writeString (String string, boolean append) {
writeString(string, append, null);
}

/** Writes the specified string to the file as UTF-8.
/** Writes the specified string to the file as UTF-8. Parent directories will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @param charset May be null to use the default charset.
* @throw GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
Expand All @@ -291,7 +293,8 @@ public void writeString (String string, boolean append, String charset) {
}

/** Returns the paths to the children of this directory. Returns an empty list if this file handle represents a file and not a
* directory. On the desktop, an internal handle to a directory on the classpath will return a zero length array.
* directory. On the desktop, an {@link FileType#Internal} handle to a directory on the classpath will return a zero length
* array.
* @throw GdxRuntimeException if this file is an {@link FileType#Classpath} file. */
public FileHandle[] list () {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot list a classpath directory: " + file);
Expand All @@ -304,8 +307,8 @@ public FileHandle[] list () {
}

/** Returns the paths to the children of this directory with the specified suffix. Returns an empty list if this file handle
* represents a file and not a directory. On the desktop, an internal handle to a directory on the classpath will return a zero
* length array.
* represents a file and not a directory. On the desktop, an {@link FileType#Internal} handle to a directory on the classpath
* will return a zero length array.
* @throw GdxRuntimeException if this file is an {@link FileType#Classpath} file. */
public FileHandle[] list (String suffix) {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot list a classpath directory: " + file);
Expand All @@ -327,8 +330,9 @@ public FileHandle[] list (String suffix) {
return handles;
}

/** Returns true if this file is a directory. Always returns false for classpath files. On Android, an internal handle to an
* empty directory will return false. On the desktop, an internal handle to a directory on the classpath will return false. */
/** Returns true if this file is a directory. Always returns false for classpath files. On Android, an {@link FileType#Internal}
* handle to an empty directory will return false. On the desktop, an {@link FileType#Internal} handle to a directory on the
* classpath will return false. */
public boolean isDirectory () {
if (type == FileType.Classpath) return false;
return file().isDirectory();
Expand Down Expand Up @@ -361,7 +365,7 @@ public void mkdirs () {
file().mkdirs();
}

/** Returns true if the file exists. On Android, a classpath handle to a directory will always return false. */
/** Returns true if the file exists. On Android, a {@link FileType#Classpath} handle to a directory will always return false. */
public boolean exists () {
switch (type) {
case Internal:
Expand Down Expand Up @@ -391,7 +395,7 @@ public boolean deleteDirectory () {

/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a
* file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination
* doesn't exist, necessary parent directories are created and this file is copied to the destination. If this handle is a
* doesn't exist, {@link #mkdirs()} is called on the destination and this file is copied into it. If this handle is a
* directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is a directory,
* this directory is copied recursively into it as a subdirectory, overwriting existing files, or 3) if the destination doesn't
* exist, {@link #mkdirs()} is called on the destination and this directory is copied recursively into it as a subdirectory.
Expand Down Expand Up @@ -442,6 +446,13 @@ public long length () {
return file().length();
}

/** Returns the last modified time in milliseconds for this file. Zero is returned if the file doesn't exist. Zero is returned
* for {@link FileType#Classpath} files. On Android, zero is returned for {@link FileType#Internal} files. On the desktop, zero
* is returned for {@link FileType#Internal} files on the classpath. */
public long lastModified () {
return file().lastModified();
}

public String toString () {
return file.getPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ public Cell stack (Actor... actor) {
return layout.stack(actor);
}

/** Creates a new table with the same Skin, Stage, and AssetManager as this table. */
public Table table () {
return layout.getToolkit().newTable(this);
}

/** Indicates that subsequent cells should be added to a new row and returns the cell values that will be used as the defaults
* for all cells in the new row.
* @see TableLayout#row() */
Expand Down
11 changes: 0 additions & 11 deletions gdx/src/com/badlogic/gdx/utils/NumberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,4 @@ public static long doubleToLongBits (double value) {
public static double longBitsToDouble (long value) {
return Double.longBitsToDouble(value);
}

public static void main (String[] args) throws Exception {
int i = 0;
while (true) {
float asFloat = Float.intBitsToFloat(i);
int backToInt = Float.floatToRawIntBits(asFloat);
if (i != backToInt) System.out.println("fail! " + Integer.toHexString(i));
if (i == 0xffffffff) break;
i++;
}
}
}

0 comments on commit f7dfcfd

Please sign in to comment.