当前位置: 首页>>代码示例>>Java>>正文


Java FileHandle类代码示例

本文整理汇总了Java中com.badlogic.gdx.files.FileHandle的典型用法代码示例。如果您正苦于以下问题:Java FileHandle类的具体用法?Java FileHandle怎么用?Java FileHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileHandle类属于com.badlogic.gdx.files包,在下文中一共展示了FileHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fullPathForFileName

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
/**
 * 从搜索队列中找到完整文件路径
 * @param fileName
 * @return
 */
public FullFilePath fullPathForFileName(String fileName) {
    FullFilePath ret = _fullPathCache.get(fileName);
    if(ret != null) {
        return ret;
    }
    
    for(int i = 0; i < _searchPathArray.size; ++i) {
        FullFilePath curr = _searchPathArray.get(i);
        System.out.println(curr);
        FileHandle fh = Gdx.files.getFileHandle(curr.path + fileName, curr.type);
        if(fh != null && fh.exists()) {
            ret = curr;
            break;
        }
    }
    
    if(ret == null) {
        ret = _defaultResRootPath;
    }
    
    _fullPathCache.put(fileName, ret);
    return ret;
}
 
开发者ID:mingwuyun,项目名称:cocos2d-java,代码行数:29,代码来源:FileUtils.java

示例2: createSave

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
public static Save createSave(String name, String generatorID, Gamemode gamemode, String seedString) {
  if (name != null) name = name.trim();
  if (name == null || name.isEmpty()) name = "world-" + Integer.toHexString(MathUtils.random.nextInt());
  FileHandle folder = getSavesFolder();
  FileHandle handle = folder.child(name);
  handle.mkdirs();
  Compatibility.get().nomedia(handle);
  Save s = new Save(name, handle);

  SaveOptions options = new SaveOptions();
  options.setWorldSeed(seedString);
  options.worldType = generatorID;
  options.worldGamemode = gamemode;
  s.setSaveOptions(options);

  return s;
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:18,代码来源:ClientSaveManager.java

示例3: 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

示例4: convertToDex

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
private FileHandle convertToDex(FileHandle fileHandle) throws Exception {
  String inputHash = hashFile(fileHandle);
  
  FileHandle cacheDir = new FileHandle(androidCompatibility.androidLauncher.getCacheDir());
  FileHandle dexDir = cacheDir.child("converted_mod_dex");
  dexDir.mkdirs();
  FileHandle dexFile = dexDir.child(inputHash + ".dex");
  
  if (!dexFile.exists()) {
    Log.warning("Trying to convert jar to dex: " + fileHandle.file().getAbsolutePath());
    com.android.dx.command.dexer.Main.Arguments arguments = new com.android.dx.command.dexer.Main.Arguments();
    arguments.parse(new String[]{"--output=" + dexFile.file().getAbsolutePath(), fileHandle.file().getAbsolutePath()});
    int result = com.android.dx.command.dexer.Main.run(arguments);
    if (result != 0) throw new CubesException("Failed to convert jar to dex [" + result + "]: " + fileHandle.file().getAbsolutePath());
    Log.warning("Converted jar to dex: " + fileHandle.file().getAbsolutePath());
  }
  
  return dexFile;
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:20,代码来源:AndroidModLoader.java

示例5: getImageFilePath

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
public static FileHandle getImageFilePath(String path){
    StringBuilder stringBuilder = new StringBuilder();
    String projectPath = getProjectPath();
    stringBuilder.append(projectPath);
    if (!projectPath.isEmpty()){
        if (!projectPath.endsWith("/")){
            stringBuilder.append("/");
        }
        stringBuilder.append(path==null?"":path);
        String imagePath = stringBuilder.toString();
        FileHandle fileHandle = new FileHandle(imagePath);
        if (fileHandle.exists() && fileHandle.file().isFile()){
            return fileHandle;
        } else{
            return Gdx.files.internal("badlogic.jpg");
        }


    }
    return null;
}
 
开发者ID:whitecostume,项目名称:libgdx_ui_editor,代码行数:22,代码来源:Config.java

示例6: writePixmaps

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 *
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 *
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 *
 * Note: None of the pixmaps will be disposed.
 *
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
    if (pages==null || pages.length==0)
        throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

    String[] pageRefs = new String[pages.length];

    for (int i=0; i<pages.length; i++) {
        String ref = pages.length==1 ? (fileName+".png") : (fileName+"_"+i+".png");

        //the ref for this image
        pageRefs[i] = ref;

        //write the PNG in that directory
        PixmapIO.writePNG(outputDir.child(ref), pages[i]);
    }
    return pageRefs;
}
 
开发者ID:TudorRosca,项目名称:enklave,代码行数:32,代码来源:BitmapFontWriter.java

示例7: toggleTracking

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
public static void toggleTracking() {
    synchronized (enabled) {
        if (enabled.get()) {
            stopTracking();
            FileHandle dir = Compatibility.get().getBaseFolder().child("performance");
            Compatibility.get().nomedia(dir);
            dir.mkdirs();
            try {
                save(dir.child(System.currentTimeMillis() + ".cbpf").file());
            } catch (IOException e) {
                Debug.crash(e);
            }
        } else {
            clear();
            startTracking();
        }
    }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:19,代码来源:Performance.java

示例8: loadMap

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
/**
 * Lädt die Map aus der Datei in den Speicher.
 *
 * Wird von {@link #initMap()} aufgerufen.
 */
private void loadMap()
{
    FileHandle mapFile = Gdx.files.internal("data/maps/" + mapName + ".tmx");

    if (!mapFile.exists() || mapFile.isDirectory())
    {
        Gdx.app.error("ERROR", "The map file " + mapName + ".tmx doesn't exists!");
        levelManager.exitToMenu();
        return;
    }

    TmxMapLoader.Parameters mapLoaderParameters = new TmxMapLoader.Parameters();
    mapLoaderParameters.textureMagFilter = Texture.TextureFilter.Nearest;
    mapLoaderParameters.textureMinFilter = Texture.TextureFilter.Nearest;

    tileMap = new TmxMapLoader().load(mapFile.path(), mapLoaderParameters);
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:23,代码来源:Level.java

示例9: load

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
private static Multimap<JsonStage, JsonValue> load(Map<String, FileHandle> map) throws IOException {
 try {
  Multimap<JsonStage, JsonValue> m = new Multimap<JsonStage, JsonValue>();
  for (Map.Entry<String, FileHandle> entry : map.entrySet()) {
    JsonStage stage = null;
    if (entry.getKey().startsWith("block")) {
      stage = JsonStage.BLOCK;
    } else if (entry.getKey().startsWith("item")) {
      stage = JsonStage.ITEM;
    } else if (entry.getKey().startsWith("recipe")) {
      stage = JsonStage.RECIPE;
    } else {
      throw new CubesException("Invalid json file path \"" + entry.getKey() + "\"");
    }

    Reader reader = entry.getValue().reader();
  
      m.put(stage, Json.parse(reader));
    } 
  }finally {
      reader.close();
    }
  return m;
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:25,代码来源:JsonLoader.java

示例10: read

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
public static boolean read() {
    FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");

    try {
        Reader reader = fileHandle.reader();
        JsonObject json = Json.parse(reader).asObject();
        reader.close();

        for (Member member : json) {
            Setting setting = set.settings.get(member.getName());
            setting.readJson(member.getValue());
        }

        return true;
    } catch (Exception e) {
        Log.error("Failed to read settings", e);
        fileHandle.delete();
        return false;
    }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:21,代码来源:Settings.java

示例11: 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

示例12: Save

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
public Save(String name, FileHandle fileHandle, boolean readOnly) {
    this.name = name;
    this.fileHandle = fileHandle;
    this.readOnly = readOnly;

    if (!this.readOnly) {
        this.fileHandle.mkdirs();
        Compatibility.get().nomedia(this.fileHandle);

        folderArea().mkdirs();
        Compatibility.get().nomedia(folderArea());

        folderPlayer().mkdirs();
        Compatibility.get().nomedia(folderPlayer());

        folderCave().mkdirs();
        Compatibility.get().nomedia(folderCave());
    }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:20,代码来源:Save.java

示例13: takeScreenshot

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
public static void takeScreenshot() {
  Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
  FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots");
  dir.mkdirs();
  FileHandle f = dir.child(System.currentTimeMillis() + ".png");
  try {
    PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
    try {
      writer.setFlipY(true);
      writer.write(f, pixmap);
    } finally {
      writer.dispose();
    }
  } catch (IOException ex) {
    throw new CubesException("Error writing PNG: " + f, ex);
  } finally {
    pixmap.dispose();
  }
  Log.info("Took screenshot '" + f.file().getAbsolutePath() + "'");
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:21,代码来源:Graphics.java

示例14: getNextModFile

import com.badlogic.gdx.files.FileHandle; //导入依赖的package包/类
@Override
public ModFile getNextModFile() throws IOException {
    FileHandle file = files.pollFirst();
    if (file != null)
        return new FolderModFile(file);
    FileHandle folder = folders.pollFirst();
    if (folder == null)
        return null;
    for (FileHandle f : folder.list()) {
        if (f.isDirectory()) {
            folders.add(f);
        } else {
            files.add(f);
        }
    }
    return new FolderModFile(folder);
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:18,代码来源:ModInputStream.java

示例15: 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


注:本文中的com.badlogic.gdx.files.FileHandle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。