/** Attempts to memory map this file in READ_ONLY mode. Android files must not be compressed. * @throws GdxRuntimeException if this file handle represents a directory, doesn't exist, or could not be read, or memory mapping fails, or is a {@link FileType#Classpath} file. */ public ByteBuffer map () { return map(MapMode.READ_ONLY); }
/** Attempts to memory map this file in READ_ONLY mode. Android files must not be compressed. * @throws GdxRuntimeException if this file handle represents a directory, doesn't exist, or could not be read, or memory mapping fails, or is a {@link FileType#Classpath} file. */ public ByteBuffer map () { return map(MapMode.READ_ONLY); }
public ByteBuffer map (FileChannel.MapMode mode) { if (type == FileType.Internal) { FileInputStream input = null; try { AssetFileDescriptor fd = getAssetFileDescriptor(); long startOffset = fd.getStartOffset(); long declaredLength = fd.getDeclaredLength(); input = new FileInputStream(fd.getFileDescriptor()); ByteBuffer map = input.getChannel().map(mode, startOffset, declaredLength); map.order(ByteOrder.nativeOrder()); return map; } catch (Exception ex) { throw new GdxRuntimeException("Error memory mapping file: " + this + " (" + type + ")", ex); } finally { StreamUtils.closeQuietly(input); } } return super.map(mode); }
public ByteBuffer map (FileChannel.MapMode mode) { if (type == FileType.Internal) { FileInputStream input = null; try { AssetFileDescriptor fd = getAssetFileDescriptor(); long startOffset = fd.getStartOffset(); long declaredLength = fd.getDeclaredLength(); input = new FileInputStream(fd.getFileDescriptor()); ByteBuffer map = input.getChannel().map(mode, startOffset, declaredLength); map.order(ByteOrder.nativeOrder()); return map; } catch (Exception ex) { throw new GdxRuntimeException("Error memory mapping file: " + this + " (" + type + ")", ex); } finally { StreamUtils.closeQuietly(input); } } return super.map(mode); }
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); }
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); }
/** Attempts to memory map this file in READ_ONLY mode. Android files must not be compressed. * @throws GdxRuntimeException if this file handle represents a directory, doesn't exist, or could not be read, or memory mapping fails, or is a {@link FileType#Classpath} file. */ public ByteBuffer map () { return map(MapMode.READ_ONLY); }
buffer = fontFile.map(); } catch (GdxRuntimeException e) {