private int estimateLength () { int length = (int)length(); return length != 0 ? length : 512; }
private int estimateLength () { int length = (int)length(); return length != 0 ? length : 512; }
@Override public void create () { FileHandle handle = Gdx.files.internal("data/arial.ttf"); bytes = new byte[(int)handle.length()]; DataInputStream in = new DataInputStream(handle.read()); for (int i = 0; i < 100; i++) { try { bytes[i] = in.readByte(); } catch (IOException e) { e.printStackTrace(); } } }
public long length () { if (type == FileType.Internal) { AssetFileDescriptor fileDescriptor = null; try { fileDescriptor = assets.openFd(file.getPath()); return fileDescriptor.getLength(); } catch (IOException ignored) { } finally { if (fileDescriptor != null) { try { fileDescriptor.close(); } catch (IOException e) { } ; } } } return super.length(); }
public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) { final int len = (int)fileHandle.length(); if (len <= 0) throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified"); java.nio.ByteBuffer buff = com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(len); buff.put(fileHandle.readBytes()); buff.position(0); boolean result = loadFileFromMemory(buff, len); com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff); return result; }
public long length () { if (type == FileType.Internal) { AssetFileDescriptor fileDescriptor = null; try { fileDescriptor = assets.openFd(file.getPath()); return fileDescriptor.getLength(); } catch (IOException ignored) { } finally { if (fileDescriptor != null) { try { fileDescriptor.close(); } catch (IOException e) { } ; } } } return super.length(); }
public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) { final int len = (int)fileHandle.length(); if (len <= 0) throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified"); java.nio.ByteBuffer buff = com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(len); buff.put(fileHandle.readBytes()); buff.position(0); boolean result = loadFileFromMemory(buff, len); com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff); return result; }
private void testClasspath () throws IOException { // no classpath support on ios if (Gdx.app.getType() == ApplicationType.iOS) return; FileHandle handle = Gdx.files.classpath("com/badlogic/gdx/utils/arial-15.png"); if (!handle.exists()) fail(); if (handle.isDirectory()) fail(); try { handle.delete(); fail(); } catch (Exception expected) { } try { handle.list(); fail(); } catch (Exception expected) { } try { handle.read().close(); fail(); } catch (Exception ignored) { } FileHandle dir = Gdx.files.classpath("com/badlogic/gdx/utils"); if (dir.isDirectory()) fail(); FileHandle child = dir.child("arial-15.fnt"); if (!child.name().equals("arial-15.fnt")) fail(); if (!child.nameWithoutExtension().equals("arial-15")) fail(); if (!child.extension().equals("fnt")) fail(); handle.read().close(); if (handle.readBytes().length != handle.length()) fail(); }
output.close(); if (!handle.exists()) fail(); if (handle.length() != 3) fail(); FileHandle copy = Gdx.files.local(path + "-copy"); copy.delete(); handle.copyTo(copy); if (!copy.exists()) fail(); if (copy.length() != 3) fail(); FileHandle move = Gdx.files.local(path + "-move"); move.delete(); copy.moveTo(move); if (!move.exists()) fail(); if (move.length() != 3) fail(); move.deleteDirectory(); if (move.exists()) fail(); output.write("cow".getBytes()); output.close(); if (handle.length() != 6) fail(); input = handle.read(); if (input.read(bytes) != 6) fail();
output.close(); if (!handle.exists()) fail(); if (handle.length() != 3) fail(); FileHandle copy = Gdx.files.absolute(path + "-copy"); copy.delete(); handle.copyTo(copy); if (!copy.exists()) fail(); if (copy.length() != 3) fail(); FileHandle move = Gdx.files.absolute(path + "-move"); move.delete(); copy.moveTo(move); if (!move.exists()) fail(); if (move.length() != 3) fail(); move.deleteDirectory(); if (move.exists()) fail(); output.write("cow".getBytes()); output.close(); if (handle.length() != 6) fail(); input = handle.read(); if (input.read(bytes) != 6) fail();
public Face newFace(FileHandle fontFile, int faceIndex) { ByteBuffer buffer = null; try { buffer = fontFile.map(); } catch (GdxRuntimeException ignored) { // OK to ignore, some platforms do not support file mapping. } if (buffer == null) { InputStream input = fontFile.read(); try { int fileSize = (int)fontFile.length(); if (fileSize == 0) { // Copy to a byte[] to get the size, then copy to the buffer. byte[] data = StreamUtils.copyStreamToByteArray(input, 1024 * 16); buffer = BufferUtils.newUnsafeByteBuffer(data.length); BufferUtils.copy(data, 0, buffer, data.length); } else { // Trust the specified file size. buffer = BufferUtils.newUnsafeByteBuffer(fileSize); StreamUtils.copyStream(input, buffer); } } catch (IOException ex) { throw new GdxRuntimeException(ex); } finally { StreamUtils.closeQuietly(input); } } return newMemoryFace(buffer, faceIndex); }
output.close(); if (!handle.exists()) fail(); if (handle.length() != 3) fail(); FileHandle copy = Gdx.files.external(path + "-copy"); copy.delete(); handle.copyTo(copy); if (!copy.exists()) fail(); if (copy.length() != 3) fail(); FileHandle move = Gdx.files.external(path + "-move"); move.delete(); copy.moveTo(move); if (!move.exists()) fail(); if (move.length() != 3) fail(); move.deleteDirectory(); if (move.exists()) fail(); output.write("cow".getBytes()); output.close(); if (handle.length() != 6) fail(); input = handle.read(); if (input.read(bytes) != 6) fail();
public Face newFace(FileHandle fontFile, int faceIndex) { ByteBuffer buffer = null; try { buffer = fontFile.map(); } catch (GdxRuntimeException ignored) { // OK to ignore, some platforms do not support file mapping. } if (buffer == null) { InputStream input = fontFile.read(); try { int fileSize = (int)fontFile.length(); if (fileSize == 0) { // Copy to a byte[] to get the size, then copy to the buffer. byte[] data = StreamUtils.copyStreamToByteArray(input, 1024 * 16); buffer = BufferUtils.newUnsafeByteBuffer(data.length); BufferUtils.copy(data, 0, buffer, data.length); } else { // Trust the specified file size. buffer = BufferUtils.newUnsafeByteBuffer(fileSize); StreamUtils.copyStream(input, buffer); } } catch (IOException ex) { throw new GdxRuntimeException(ex); } finally { StreamUtils.closeQuietly(input); } } return newMemoryFace(buffer, faceIndex); }
Gdx.app.log("UBJsonTest", "File size is " + Gdx.files.external(fn).length()); UBJsonReader ur = new UBJsonReader(); ur.oldFormat = false;
private void printHandleInfo(FileHandle handle) { System.out.println(handle.isDirectory() ? "Directory info" : "File info"); System.out.println("Name: " + handle.name()); System.out.println("Name without extension: " + handle.nameWithoutExtension()); System.out.println("Extension: " + handle.extension()); System.out.println("Last modified in ms " + handle.lastModified()); System.out.println("Path " + handle.path()); System.out.println("Path without extension " + handle.pathWithoutExtension()); if (!handle.isDirectory()) { System.out.println("Size: " + handle.length() + " bytes"); } System.out.println(); }
public boolean loadFile(final com.badlogic.gdx.files.FileHandle fileHandle) { final int len = (int)fileHandle.length(); if (len <= 0) throw new com.badlogic.gdx.utils.GdxRuntimeException("Incorrect file specified"); java.nio.ByteBuffer buff = com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(len); buff.put(fileHandle.readBytes()); buff.position(0); boolean result = loadFileFromMemory(buff, len); com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(buff); return result; }
private FileHandleMetadata (FileHandle file) { this.name = file.name(); this.directory = file.isDirectory(); this.lastModified = file.lastModified(); this.length = file.length(); this.readableFileSize = FileUtils.readableFileSize(length); }
private void updatePageInfo() { if (atlasPage == null) return; setPageDimens(atlasPage.getWidth(), atlasPage.getHeight()); setCurrentPage(atlasPage.getPageIndex() + 1); setPagesAmount(atlasPage.getAtlasModel().getPages().size); setFileSize(atlasPage.getAtlasModel().getAtlasData().getPages().get(atlasPage.getPageIndex()).textureFile.length()); }