Example usage for com.badlogic.gdx.files FileHandle read

List of usage examples for com.badlogic.gdx.files FileHandle read

Introduction

In this page you can find the example usage for com.badlogic.gdx.files FileHandle read.

Prototype

public InputStream read() 

Source Link

Document

Returns a stream for reading this file as bytes.

Usage

From source file:Generator.java

License:Open Source License

private static void renamePrefixes(String path, String prefix, String newPrefix) {
    Files files = new LwjglFiles();
    for (FileHandle fileHandle : files.local(path).list()) {
        if (fileHandle.name().startsWith(prefix)) {
            String newName = newPrefix + fileHandle.name().substring(prefix.length());
            println(fileHandle.name() + " -> " + newName);
            fileHandle.sibling(newName).write(fileHandle.read(), false);
            fileHandle.delete();//w  ww  . jav a2s .  co m
        }
    }
}

From source file:com.andgate.ikou.io.LevelDatabaseService.java

License:Open Source License

public static LevelData getLevelData(final FileHandle levelFile, ProgressDatabase progressDB)
        throws IOException {
    final String levelName = levelFile.nameWithoutExtension();
    final int completedFloors = progressDB.getFloorsCompleted(levelName);

    final InputStream levelIn = new GZIPInputStream(levelFile.read());
    final int totalFloors = levelIn.read();
    levelIn.close();/*from   w w w.j  ava  2s . co  m*/

    return new LevelData(levelName, totalFloors, completedFloors);
}

From source file:com.andgate.ikou.io.LevelService.java

License:Open Source License

public static Level read(final FileHandle levelFile) throws IOException {
    Level level = null;/*w  w w. ja v  a  2 s.  c  o m*/

    if (levelFile.exists() && levelFile.extension().equals(Constants.LEVEL_EXTENSION_NO_DOT)) {
        InputStream levelIn = new GZIPInputStream(levelFile.read());
        Reader reader = new BufferedReader(new InputStreamReader(levelIn));
        JsonReader jsonReader = new JsonReader(reader);

        try {
            // Skip the first int, it's just the floor numbers.
            levelIn.read();
            Gson gson = new Gson();
            level = gson.fromJson(jsonReader, Level.class);
        } finally {
            jsonReader.close();
        }
    }

    if (level == null) {
        final String errorMessage = "Failed to load level \"" + levelFile.path() + levelFile.name() + "\"";
        throw new IOException(errorMessage);
    }

    return level;
}

From source file:com.badlydrawngames.general.Config.java

License:Apache License

private static Properties instance() {
    if (null == properties) {
        properties = new Properties();
        FileHandle fh = Gdx.files.internal(PROPERTIES_FILE);
        InputStream inStream = fh.read();
        try {/*  w ww .  java2 s .c o m*/
            properties.load(inStream);
            inStream.close();
        } catch (IOException e) {
            if (inStream != null) {
                try {
                    inStream.close();
                } catch (IOException ex) {
                }
            }
        }
    }
    return properties;
}

From source file:com.bagon.matchteam.mtx.managers.FileManager.java

License:Apache License

/**
 * Read lines from text file.//from  w w w. j a  v  a2 s .  c  o m
 * 
 * @param strFile
 *            file to read
 * @param lineNumber
 *            line number to read
 * @param fileType
 *            the type of file to retrieve file (INTERNAL, LOCAL, EXTERNAL)
 * */
public static String readLine(String strFile, int lineNumber, FileType fileType) {
    // Identify file type and get storage location
    FileHandle file = getFile(strFile, fileType);

    // Start buffered reader
    BufferedReader reader = new BufferedReader(new InputStreamReader(file.read()));
    String currentLine = null;
    int counter = 0;
    try {
        while ((currentLine = reader.readLine()) != null) {
            if (counter == lineNumber) {
                MtxLogger.log(logActive, true, logTag, "READ LINE: " + currentLine);
                break;
            }
            counter++;
        }
        reader.close();
    } catch (IOException e) {
        MtxLogger.log(logActive, true, logTag,
                "CANT READ LINE: File: " + strFile + ", Line Number: " + lineNumber);
        e.printStackTrace();
    }
    return currentLine;
}

From source file:com.bagon.matchteam.mtx.managers.FileManager.java

License:Apache License

private static ArrayList<String> getUpdatedTextInfo(String strFile, int lineNumber, String newValue) {
    ArrayList<String> lineByLineTextList = new ArrayList<String>();
    FileHandle file = Gdx.files.local(strFile);
    BufferedReader reader = new BufferedReader(new InputStreamReader(file.read()));
    String currentLine = null;/*from   w w  w.j ava2 s  .c  o  m*/
    int counter = 0;
    try {
        while ((currentLine = reader.readLine()) != null) {
            if (counter == lineNumber) {
                MtxLogger.log(logActive, true, logTag,
                        "WRITE EXISTING LINE: OLD: " + currentLine + " - NEW: " + newValue);
                lineByLineTextList.add(newValue);
            } else {
                lineByLineTextList.add(currentLine);
            }
            counter++;
        }
        reader.close();
    } catch (IOException e) {
    }
    return lineByLineTextList;
}

From source file:com.bagon.matchteam.mtx.managers.FileManager.java

License:Apache License

/**
 * Get number of lines in a text file//from   ww w . j  a va2  s  .  co  m
 * */
public static int getNumberOflInesInTextFile(String strFile, FileType fileType) {
    FileHandle file = getFile(strFile, fileType);
    BufferedReader reader = new BufferedReader(new InputStreamReader(file.read()));
    currentLine = "";
    int counter = 0;
    try {
        while ((currentLine = reader.readLine()) != null) {
            counter++;
        }
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Gdx.app.log("SettingLog", "NUMBER OF LINES: " + file.name() + ": " + counter);
    return counter;
}

From source file:com.bladecoder.engine.i18n.I18NControl.java

License:Apache License

@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader,
        boolean reload) throws IllegalAccessException, InstantiationException, IOException {
    String bundleName = toBundleName(baseName, locale);
    String resourceName = toResourceName(bundleName, "properties");
    ResourceBundle bundle = null;
    InputStream inputStream = null;

    FileHandle fileHandle = EngineAssetManager.getInstance().getAsset(resourceName);

    if (FileUtils.exists(fileHandle)) {
        try {//from w ww.  j a  v  a2  s  .  c  om
            // inputStream = loader.getResourceAsStream(resourceName);
            inputStream = fileHandle.read();
            bundle = new PropertyResourceBundle(new InputStreamReader(inputStream, encoding));
        } finally {
            if (inputStream != null)
                inputStream.close();
        }
    }
    return bundle;
}

From source file:com.blindtigergames.werescrewed.graphics.particle.ParticleEffect.java

License:Apache License

public void loadEmitters(FileHandle effectFile) {
    InputStream input = effectFile.read();
    emitters.clear();/*from  ww  w .  j a v  a 2  s . co m*/
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(input), 512);
        while (true) {
            ParticleEmitter emitter = new ParticleEmitter(reader);
            reader.readLine();
            emitter.setImagePath(reader.readLine());
            emitters.add(emitter);
            if (reader.readLine() == null)
                break;
            if (reader.readLine() == null)
                break;
        }
    } catch (IOException ex) {
        throw new GdxRuntimeException("Error loading effect: " + effectFile, ex);
    } finally {
        try {
            if (reader != null)
                reader.close();
        } catch (IOException ex) {
        }
    }
}

From source file:com.github.fauu.helix.graphics.ParticleEffect.java

License:Apache License

public void loadEmitters(FileHandle effectFile) {
    InputStream input = effectFile.read();
    emitters.clear();/*ww w  .j ava 2s.  c  o m*/
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(input), 512);
        while (true) {
            ParticleEmitter emitter = new ParticleEmitter(reader);
            emitters.add(emitter);
            if (reader.readLine() == null)
                break;
            if (reader.readLine() == null)
                break;
        }
    } catch (IOException ex) {
        throw new GdxRuntimeException("Error loading effect: " + effectFile, ex);
    } finally {
        StreamUtils.closeQuietly(reader);
    }
}