當前位置: 首頁>>代碼示例>>Java>>正文


Java FileHandle.read方法代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:22,代碼來源:AndroidModLoader.java

示例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;
	}
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:26,代碼來源:SaveAreaIO.java

示例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;
	}
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:19,代碼來源:Save.java

示例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);
  }
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:21,代碼來源:AndroidModLoader.java

示例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;
  }
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:26,代碼來源:SaveAreaIO.java

示例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;
  }
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:17,代碼來源:Save.java

示例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);
    }
}
 
開發者ID:gradualgames,項目名稱:ggvm,代碼行數:18,代碼來源:GGVmApplication.java

示例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();
}
 
開發者ID:kurtyu,項目名稱:PixelDungeonTC,代碼行數:7,代碼來源:Game.java


注:本文中的com.badlogic.gdx.files.FileHandle.read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。