List of usage examples for com.badlogic.gdx.files FileHandle FileHandle
public FileHandle(File file)
From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java
License:Apache License
/** Batch convert all files with the {@code g3dj} extension inside a folder to the G3DB format (Binary JSON). * /*from w ww. j a v a 2 s .c o m*/ * @param args First argument is the folder and it needs to be an absolute path. Optionaly the second argument is "true" or * "false" (without quotes) to specify if G3DB files already in the folder can be overwritten ("true" for YES, the * default). * @throws Exception */ public static void main(String[] args) throws Exception { if (args == null || args.length == 0) { throw new Exception( "You need to specify at least the input folder. Ex: java G3DBConverter /path/to/g3dmodels"); } FileHandle inputFolder = new FileHandle(args[0]); boolean overwrite = true; if (args.length >= 2 && "false".equalsIgnoreCase(args[1])) { overwrite = false; } G3DBConverter converter = new G3DBConverter(); converter.convertFolder(inputFolder, overwrite); }
From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java
License:Apache License
/** <p> * Convert a text JSON file into binary JSON. The new file will be saved in the same folder as the original one with the * {@code gd3b} extension./*w ww . ja v a 2 s . c om*/ * </p> * * @param g3djFile Handle to the original G3DJ file. * @param overwrite If {@code true} the new file will overwrite any previous file with the same name. Otherwise append a * counter at the end of the file name to make it unique. * @throws IOException If there's an exception while reading the input file or writing the output file. */ public void convert(FileHandle g3djFile, boolean overwrite) throws IOException { FileHandle newFile = new FileHandle(g3djFile.pathWithoutExtension() + ".g3db"); int noOverwriteCounter = 0; while (!overwrite && newFile.exists()) { newFile = new FileHandle(g3djFile.pathWithoutExtension() + "(" + (++noOverwriteCounter) + ").g3db"); } OutputStream fileOutputStream = newFile.write(false); UBJsonWriter writer = new UBJsonWriter(fileOutputStream); JsonReader reader = new JsonReader(); try { JsonValue root = reader.parse(g3djFile); writeObject(root, writer); } finally { writer.close(); } }
From source file:CB_Core.Api.LiveMapQue.java
License:Open Source License
public static CB_List<Cache> loadDescLiveFromCache(SearchLiveMap requestSearch) { String path = requestSearch.descriptor.getLocalCachePath(LIVE_CACHE_NAME) + LIVE_CACHE_EXTENTION; String result = null;/*from w w w . j av a 2 s .c o m*/ FileHandle fh = new FileHandle(path); try { BufferedReader br = fh.reader(1000); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } result = sb.toString(); br.close(); } catch (IOException e) { e.printStackTrace(); } // parseResult CB_List<Cache> cacheList = new CB_List<Cache>(); if (result != null && result.length() > 0) { if (gpxFilename == null) { Category category = CoreSettingsForward.Categories.getCategory("API-Import"); gpxFilename = category.addGpxFilename("API-Import"); } SEARCH_API.ParseJsonResult(requestSearch, cacheList, apiLogs, apiImages, gpxFilename.Id, result, (byte) 1, true); return cacheList; } return null; }
From source file:CB_Core.DAO.CacheListDAO.java
License:Open Source License
public void delCacheImagesByPath(String path, ArrayList<String> list) { for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { final String GcCode = iterator.next().toLowerCase(); String directory = path + "/" + GcCode.substring(0, 4); if (!FileIO.DirectoryExists(directory)) continue; FileHandle dir = new FileHandle(directory); FileHandle[] files = dir.list(); for (int i = 0; i < files.length; i++) { // simplyfied for startswith gccode, thumbs_gccode + ooverwiewthumbs_gccode if (!files[i].name().toLowerCase().contains(GcCode)) continue; String filename = directory + "/" + files[i].name(); FileHandle file = new FileHandle(filename); if (file.exists()) { if (!file.delete()) Log.err(log, "Error deleting : " + filename); }/*from w ww . j av a2 s . c o m*/ } } }
From source file:com.avechados.main.TiledMapHelper.java
License:Apache License
public static void main(String[] args) { System.out.println("--- map ---"); TiledMap map = TiledLoader.createMap(new FileHandle("res/NatalArena.tmx")); for (String name : map.properties.keySet()) { String value = map.properties.get(name); System.out.println("\tproperty :: " + name + ": " + value); }//from w w w . jav a2 s. c o m System.out.println(); System.out.println("--- layers ---"); for (TiledLayer layer : map.layers) { System.out.println("layer: " + layer.name); for (String name : layer.properties.keySet()) { String value = layer.properties.get(name); System.out.println("layer property :: " + name + ": " + value); } System.out.println("--- layer tiles ---"); for (int i = 0; i < layer.tiles.length; i++) { for (int j = 0; j < layer.tiles[i].length; j++) { int tileIndex = layer.tiles[i][j] - 1; String locationStr = map.getTileProperty(tileIndex, Constants.TILE_LOCATION_KEY); String groundStr = map.getTileProperty(tileIndex, Constants.TILE_GROUND_KEY); String qualifierStr = map.getTileProperty(tileIndex, Constants.TILE_QUALIFIER_KEY); System.out.println("Tile[" + i + "][" + j + "] = " + tileIndex + "(" + locationStr + "," + groundStr + "," + qualifierStr + ")"); } System.out.println(); } } System.out.println(); System.out.println("--- groups ---"); for (TiledObjectGroup group : map.objectGroups) { System.out.println("group: " + group.name); for (String name : group.properties.keySet()) { String value = group.properties.get(name); System.out.println("\tproperty :: " + name + ": " + value); } for (TiledObject object : group.objects) { System.out.println("\tobject: " + object.name); for (String name : object.properties.keySet()) { String value = object.properties.get(name); System.out.println("\t\tproperty :: " + name + ": " + value); } } } }
From source file:com.badlogic.gdx.tests.utils.AssetsFileGenerator.java
License:Apache License
public static void main(String[] args) { FileHandle file = new FileHandle(args[0]); StringBuffer list = new StringBuffer(); args[0] = args[0].replace("\\", "/"); if (!args[0].endsWith("/")) args[0] = args[0] + "/"; traverse(file, args[0], list);//from ww w . j a va 2 s.com new FileHandle(args[0] + "/assets.txt").writeString(list.toString(), false); }
From source file:com.bladecoder.engine.assets.EngineResolutionFileResolver.java
License:Apache License
@Override public FileHandle resolve(String fileName) { FileHandle originalHandle = new FileHandle(fileName); FileHandle handle = baseResolver.resolve(resolve(originalHandle, bestDesc.folder)); if (!FileUtils.exists(handle)) handle = baseResolver.resolve(fileName); return handle; }
From source file:com.bladecoder.engine.assets.EngineResolutionFileResolver.java
License:Apache License
public boolean exists(String fileName) { FileHandle originalHandle = new FileHandle(fileName); FileHandle handle = baseResolver.resolve(resolve(originalHandle, bestDesc.folder)); if (FileUtils.exists(handle)) return true; handle = baseResolver.resolve(fileName); if (FileUtils.exists(handle)) return true; return false; }
From source file:com.bladecoder.engineeditor.model.Project.java
License:Apache License
public void saveProject() throws IOException { if (projectFile != null && chapter.getId() != null && modified) { EngineLogger.setDebug();/* ww w .j ava2s.c om*/ // 1.- SAVE world.json World.getInstance().saveWorldDesc( new FileHandle(new File(projectFile.getAbsolutePath() + MODEL_PATH + "/world.json"))); // 2.- SAVE .chapter chapter.save(); // 3.- SAVE BladeEngine.properties projectConfig.store( new FileOutputStream( projectFile.getAbsolutePath() + "/" + ASSETS_PATH + "/" + Config.PROPERTIES_FILENAME), null); // 4.- SAVE I18N i18n.save(); modified = false; firePropertyChange(NOTIFY_PROJECT_SAVED); } }
From source file:com.bladecoder.engineeditor.utils.ImageUtils.java
License:Apache License
public static void scaleAtlas(File orgAtlas, File destDir, float scale) throws IOException { CustomTextureUnpacker unpacker = new CustomTextureUnpacker(); File outputDir = DesktopUtils.createTempDirectory(); String atlasParentPath = orgAtlas.getParentFile().getAbsolutePath(); TextureAtlasData atlas = new TextureAtlasData(new FileHandle(orgAtlas), new FileHandle(atlasParentPath), false);/*from w w w . java2 s. com*/ unpacker.splitAtlas(atlas, outputDir.getAbsolutePath()); createAtlas(outputDir.getAbsolutePath(), destDir.getAbsolutePath(), orgAtlas.getName(), scale, TextureFilter.Linear, TextureFilter.Linear); DesktopUtils.removeDir(outputDir.getAbsolutePath()); }