本文整理匯總了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();
}