本文整理汇总了Java中com.badlogic.gdx.files.FileHandle.read方法的典型用法代码示例。如果您正苦于以下问题:Java FileHandle.read方法的具体用法?Java FileHandle.read怎么用?Java FileHandle.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.files.FileHandle
的用法示例。
在下文中一共展示了FileHandle.read方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hashFile
import com.badlogic.gdx.files.FileHandle; //导入方法依赖的package包/类
public static String hashFile(FileHandle fileHandle) throws Exception {
InputStream inputStream = fileHandle.read();
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] bytesBuffer = new byte[1024];
int bytesRead;
int n =inputStream.read(bytesBuffer);
while ((bytesRead = n) != -1) {
digest.update(bytesBuffer, 0, bytesRead);
n=inputStream.read(bytesBuffer);
}
byte[] hashedBytes = digest.digest();
return convertByteArrayToHexString(hashedBytes);
} catch (IOException ex) {
throw new CubesException("Could not generate hash from file " + fileHandle.path(), ex);
} finally {
StreamUtils.closeQuietly(inputStream);
}
}
示例2: read
import com.badlogic.gdx.files.FileHandle; //导入方法依赖的package包/类
public static Area read(Save save, int x, int z) {
FileHandle file = file(save, x, z);
if (!file.exists()) {
// Log.warning("Area does not exist");
return null;
}
Inflater inflater = inflaterThreadLocal.get();
try {
inflater.reset();
InputStream inputStream = file.read(8192);
InflaterInputStream inflaterInputStream = new InflaterInputStream(inputStream, inflater);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inflaterInputStream);
DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);
Area area = new Area(x, z);
area.read(dataInputStream);
dataInputStream.close();
return area;
} catch (Exception e) {
Log.error("Failed to read area " + x + "," + z, e);
return null;
}
}
示例3: readCave
import com.badlogic.gdx.files.FileHandle; //导入方法依赖的package包/类
public Cave readCave(AreaReference areaReference) {
if (fileHandle == null)
return null;
FileHandle folder = folderCave();
FileHandle file = folder.child(areaReference.areaX + "_" + areaReference.areaZ);
if (!file.exists())
return null;
try {
InputStream read = file.read();
DataInputStream dataInputStream = new DataInputStream(read);
Cave cave = Cave.read(dataInputStream);
read.close();
return cave;
} catch (IOException e) {
Log.warning("Failed to read cave", e);
return null;
}
}
示例4: hashFile
import com.badlogic.gdx.files.FileHandle; //导入方法依赖的package包/类
public static String hashFile(FileHandle fileHandle) throws Exception {
InputStream inputStream = fileHandle.read();
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] bytesBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(bytesBuffer)) != -1) {
digest.update(bytesBuffer, 0, bytesRead);
}
byte[] hashedBytes = digest.digest();
return convertByteArrayToHexString(hashedBytes);
} catch (IOException ex) {
throw new CubesException("Could not generate hash from file " + fileHandle.path(), ex);
} finally {
StreamUtils.closeQuietly(inputStream);
}
}
示例5: read
import com.badlogic.gdx.files.FileHandle; //导入方法依赖的package包/类
public static Area read(Save save, int x, int z) {
FileHandle file = file(save, x, z);
if (!file.exists()) {
//Log.warning("Area does not exist");
return null;
}
Inflater inflater = inflaterThreadLocal.get();
try {
inflater.reset();
InputStream inputStream = file.read(8192);
InflaterInputStream inflaterInputStream = new InflaterInputStream(inputStream, inflater);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inflaterInputStream);
DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);
Area area = new Area(x, z);
area.read(dataInputStream);
dataInputStream.close();
return area;
} catch (Exception e) {
Log.error("Failed to read area " + x + "," + z, e);
return null;
}
}
示例6: readCave
import com.badlogic.gdx.files.FileHandle; //导入方法依赖的package包/类
public Cave readCave(AreaReference areaReference) {
if (fileHandle == null) return null;
FileHandle folder = folderCave();
FileHandle file = folder.child(areaReference.areaX + "_" + areaReference.areaZ);
if (!file.exists()) return null;
try {
InputStream read = file.read();
DataInputStream dataInputStream = new DataInputStream(read);
Cave cave = Cave.read(dataInputStream);
read.close();
return cave;
} catch (IOException e) {
Log.warning("Failed to read cave", e);
return null;
}
}
示例7: loadState
import com.badlogic.gdx.files.FileHandle; //导入方法依赖的package包/类
/**
* Loads last saved save state file.
* TODO: Implement for mobile devices.
*/
private void loadState() {
Gdx.app.log(getClass().getSimpleName(), "loadState()");
try {
FileHandle file = Gdx.files.local("state.sav");
if (file.exists()) {
InputStream inputStream = file.read();
ggvm.loadState(inputStream);
soundtrackManager.load(inputStream);
}
} catch (IOException ex) {
Gdx.app.error(getClass().getSimpleName(), "Error loading game state.", ex);
}
}
示例8: openFileInput
import com.badlogic.gdx.files.FileHandle; //导入方法依赖的package包/类
public InputStream openFileInput(String fileName) throws IOException {
final FileHandle fh = Gdx.files.external(basePath != null ? basePath + fileName : fileName);
if (!fh.exists())
throw new IOException("File " + fileName + " doesn't exist");
return fh.read();
}