当前位置: 首页>>代码示例>>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;未经允许,请勿转载。