本文整理匯總了Java中com.badlogic.gdx.Files.FileType.Classpath方法的典型用法代碼示例。如果您正苦於以下問題:Java FileType.Classpath方法的具體用法?Java FileType.Classpath怎麽用?Java FileType.Classpath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.Files.FileType
的用法示例。
在下文中一共展示了FileType.Classpath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: read
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** Returns a stream for reading this file as bytes.
* @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */
public InputStream read () {
if (type == FileType.Classpath || (type == FileType.Internal && !file().exists())
|| (type == FileType.Local && !file().exists())) {
InputStream input = FileHandle.class.getResourceAsStream("/" + file.getPath().replace('\\', '/'));
if (input == null) throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");
return input;
}
try {
return new FileInputStream(file());
} catch (Exception ex) {
if (file().isDirectory())
throw new GdxRuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex);
throw new GdxRuntimeException("Error reading file: " + file + " (" + type + ")", ex);
}
}
示例2: read
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** Returns a stream for reading this file as bytes.
* @throw GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */
public InputStream read () {
if (type == FileType.Classpath || (type == FileType.Internal && !file.exists())
|| (type == FileType.Local && !file.exists())) {
InputStream input = FileWrapper.class.getResourceAsStream("/" + file.getPath().replace('\\', '/'));
if (input == null) throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");
return input;
}
try {
return new FileInputStream(file());
} catch (Exception ex) {
if (file().isDirectory())
throw new GdxRuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex);
throw new GdxRuntimeException("Error reading file: " + file + " (" + type + ")", ex);
}
}
示例3: writer
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** 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)
return new OutputStreamWriter(output);
else
return new OutputStreamWriter(output, charset);
} catch (IOException ex) {
if (file().isDirectory())
throw new GdxRuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex);
throw new GdxRuntimeException("Error writing file: " + file + " (" + type + ")", ex);
}
}
示例4: ArchiveFileHandle
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
public ArchiveFileHandle (FileHandle zipfilehandle, String filePath, boolean init) {
super(filePath, FileType.Classpath);
this.zipfilehandle = zipfilehandle;
if (filePath.startsWith("/"))
filePath = filePath.substring(1);
if (init) {
ZipInputStream stream = new ZipInputStream(zipfilehandle.read());
try {
ZipEntry entry;
while ((entry = stream.getNextEntry()) != null)
if (entry.getName().replace('\\', '/').equals(filePath)) {
entrystream = stream;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
this.filePath = filePath;
}
示例5: moveTo
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** Moves this file to the specified file, overwriting the file if it already exists.
* @throws GdxRuntimeException if the source or destination file handle is a {@link FileType#Classpath} or
* {@link FileType#Internal} file. */
public void moveTo (FileHandle dest) {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot move a classpath file: " + file);
if (type == FileType.Internal) throw new GdxRuntimeException("Cannot move an internal file: " + file);
copyTo(dest);
delete();
if (exists() && isDirectory()) deleteDirectory();
}
示例6: length
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** Returns the length in bytes of this file, or 0 if this file is a directory, does not exist, or the size cannot otherwise be
* determined. */
public long length () {
if (type == FileType.Classpath || (type == FileType.Internal && !file.exists())) {
InputStream input = read();
try {
return input.available();
} catch (Exception ignored) {
} finally {
StreamUtils.closeQuietly(input);
}
return 0;
}
return file().length();
}
示例7: list
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** 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 {@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 FileWrapper[] list (String suffix) {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot list a classpath directory: " + file);
String[] relativePaths = file().list();
if (relativePaths == null) return new FileWrapper[0];
FileWrapper[] handles = new FileWrapper[relativePaths.length];
int count = 0;
for (int i = 0, n = relativePaths.length; i < n; i++) {
String path = relativePaths[i];
if (!path.endsWith(suffix)) continue;
handles[count] = child(path);
count++;
}
if (count < relativePaths.length) {
FileWrapper[] newHandles = new FileWrapper[count];
System.arraycopy(handles, 0, newHandles, 0, count);
handles = newHandles;
}
return handles;
}
示例8: TeaVMFileHandle
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
public TeaVMFileHandle(String fileName, FileType type) {
if (type != FileType.Internal && type != FileType.Classpath) {
throw new GdxRuntimeException("FileType '" + type + "' Not supported in GWT backend");
}
this.file = fixSlashes(fileName);
this.type = type;
}
示例9: write
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** 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.
* @throws 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 OutputStream write (boolean append) {
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 {
return new FileOutputStream(file(), append);
} catch (Exception ex) {
if (file().isDirectory())
throw new GdxRuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex);
throw new GdxRuntimeException("Error writing file: " + file + " (" + type + ")", ex);
}
}
示例10: list
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** 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 {@link FileType#Internal} handle to a directory on the classpath will return a zero length
* array.
* @throws 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);
String[] relativePaths = file().list();
if (relativePaths == null) return new FileHandle[0];
FileHandle[] handles = new FileHandle[relativePaths.length];
for (int i = 0, n = relativePaths.length; i < n; i++)
handles[i] = child(relativePaths[i]);
return handles;
}
示例11: mkdirs
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** @throws GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file. */
public void mkdirs () {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot mkdirs with a classpath file: " + file);
if (type == FileType.Internal) throw new GdxRuntimeException("Cannot mkdirs with an internal file: " + file);
file().mkdirs();
}
示例12: delete
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** Deletes this file or empty directory and returns success. Will not delete a directory that has children.
* @throws GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file. */
public boolean delete () {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot delete a classpath file: " + file);
if (type == FileType.Internal) throw new GdxRuntimeException("Cannot delete an internal file: " + file);
return file().delete();
}
示例13: deleteDirectory
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** Deletes this file or directory and all children, recursively.
* @throws GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file. */
public boolean deleteDirectory () {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot delete a classpath file: " + file);
if (type == FileType.Internal) throw new GdxRuntimeException("Cannot delete an internal file: " + file);
return deleteDirectory(file());
}
示例14: emptyDirectory
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
/** Deletes all children of this directory, recursively. Optionally preserving the folder structure.
* @throws GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file. */
public void emptyDirectory (boolean preserveTree) {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot delete a classpath file: " + file);
if (type == FileType.Internal) throw new GdxRuntimeException("Cannot delete an internal file: " + file);
emptyDirectory(file(), preserveTree);
}
示例15: GwtFileHandle
import com.badlogic.gdx.Files.FileType; //導入方法依賴的package包/類
public GwtFileHandle (Preloader preloader, String fileName, FileType type) {
if (type != FileType.Internal && type != FileType.Classpath)
throw new GdxRuntimeException("FileType '" + type + "' Not supported in GWT backend");
this.preloader = preloader;
this.file = fixSlashes(fileName);
this.type = type;
}