@Implementation public static MemoryMappedFile mmapRO(String path) throws Throwable { if (path.endsWith(TZ_DATA_1) || path.endsWith(TZ_DATA_2) || path.endsWith(TZ_DATA_3)) { InputStream is = MemoryMappedFile.class.getResourceAsStream(TZ_DATA_2); if (is == null) { throw (Throwable) exceptionClass().getConstructor(String.class, int.class) .newInstance("open", -1); } try { MemoryMappedFile memoryMappedFile = new MemoryMappedFile(0L, 0L); ShadowMemoryMappedFile shadowMemoryMappedFile = Shadow.extract(memoryMappedFile); shadowMemoryMappedFile.bytes = Streams.readFully(is); return memoryMappedFile; } catch (IOException e) { throw (Throwable) exceptionClass().getConstructor(String.class, int.class, Throwable.class) .newInstance("mmap", -1, e); } } else { throw new IllegalArgumentException("Unknown file for mmap: '" + path); } }
private void readHeader() { // byte[12] tzdata_version -- "tzdata2012f\0" // int index_offset // int data_offset // int zonetab_offset BufferIterator it = mappedFile.bigEndianIterator(); byte[] tzdata_version = new byte[12]; it.readByteArray(tzdata_version, 0, tzdata_version.length); String magic = new String(tzdata_version, 0, 6, StandardCharsets.US_ASCII); if (!magic.equals("tzdata") || tzdata_version[11] != 0) { throw new RuntimeException("bad tzdata magic: " + Arrays.toString(tzdata_version)); } version = new String(tzdata_version, 6, 5, StandardCharsets.US_ASCII); int index_offset = it.readInt(); int data_offset = it.readInt(); int zonetab_offset = it.readInt(); readIndex(it, index_offset, data_offset); readZoneTab(it, zonetab_offset, (int) mappedFile.size() - zonetab_offset); }
private boolean loadData(String path) { try { mappedFile = MemoryMappedFile.mmapRO(path); } catch (ErrnoException errnoException) { return false; } try { readHeader(); return true; } catch (Exception ex) { // Something's wrong with the file. // Log the problem and return false so we try the next choice. System.logE("tzdata file \"" + path + "\" was present but invalid!", ex); return false; } }
public TimeZone makeTimeZone(String id) throws IOException { // Work out where in the big data file this time zone is. int index = Arrays.binarySearch(ids, id); if (index < 0) { return null; } BufferIterator it = mappedFile.bigEndianIterator(); it.skip(byteOffsets[index]); return ZoneInfo.makeTimeZone(id, it); } }
public TimeZone makeTimeZone(String id) throws IOException { // Work out where in the big data file this time zone is. int index = Arrays.binarySearch(ids, id); if (index < 0) { return null; } BufferIterator it = mappedFile.bigEndianIterator(); it.skip(byteOffsets[index]); return ZoneInfo.makeTimeZone(id, it); } }
/** * Use this to mmap the whole file read-only. */ public static MemoryMappedFile mmapRO(String path) throws ErrnoException { FileDescriptor fd = Libcore.os.open(path, O_RDONLY, 0); long size = Libcore.os.fstat(fd).st_size; long address = Libcore.os.mmap(0L, size, PROT_READ, MAP_SHARED, fd, 0); Libcore.os.close(fd); return new MemoryMappedFile(address, size); }
private void readHeader() { // byte[12] tzdata_version -- "tzdata2012f\0" // int index_offset // int data_offset // int zonetab_offset BufferIterator it = mappedFile.bigEndianIterator(); byte[] tzdata_version = new byte[12]; it.readByteArray(tzdata_version, 0, tzdata_version.length); String magic = new String(tzdata_version, 0, 6, StandardCharsets.US_ASCII); if (!magic.equals("tzdata") || tzdata_version[11] != 0) { throw new RuntimeException("bad tzdata magic: " + Arrays.toString(tzdata_version)); } version = new String(tzdata_version, 6, 5, StandardCharsets.US_ASCII); int index_offset = it.readInt(); int data_offset = it.readInt(); int zonetab_offset = it.readInt(); readIndex(it, index_offset, data_offset); readZoneTab(it, zonetab_offset, (int) mappedFile.size() - zonetab_offset); }
public TimeZone makeTimeZone(String id) throws IOException { // Work out where in the big data file this time zone is. int index = Arrays.binarySearch(ids, id); if (index < 0) { return null; } BufferIterator it = mappedFile.bigEndianIterator(); it.skip(byteOffsets[index]); return ZoneInfo.makeTimeZone(id, it); } }
private boolean loadData(String path) { try { mappedFile = MemoryMappedFile.mmapRO(path); } catch (ErrnoException errnoException) { return false; } try { readHeader(); return true; } catch (Exception ex) { // Something's wrong with the file. // Log the problem and return false so we try the next choice. System.logE("tzdata file \"" + path + "\" was present but invalid!", ex); return false; } }
@Implementation public static MemoryMappedFile mmapRO(String path) throws Throwable { if (path.endsWith(TZ_DATA_1) || path.endsWith(TZ_DATA_2) || path.endsWith(TZ_DATA_3)) { InputStream is = MemoryMappedFile.class.getResourceAsStream(TZ_DATA_2); if (is == null) { throw (Throwable) exceptionClass().getConstructor(String.class, int.class) .newInstance("open", -1); } try { MemoryMappedFile memoryMappedFile = new MemoryMappedFile(0L, 0L); ShadowMemoryMappedFile shadowMemoryMappedFile = (ShadowMemoryMappedFile) ShadowExtractor.extract(memoryMappedFile); shadowMemoryMappedFile.bytes = Streams.readFully(is); return memoryMappedFile; } catch (IOException e) { throw (Throwable) exceptionClass().getConstructor(String.class, int.class, Throwable.class) .newInstance("mmap", -1, e); } } else { throw new IllegalArgumentException("Unknown file for mmap: '" + path); } }
private void readHeader() { // byte[12] tzdata_version -- "tzdata2012f\0" // int index_offset // int data_offset // int zonetab_offset BufferIterator it = mappedFile.bigEndianIterator(); byte[] tzdata_version = new byte[12]; it.readByteArray(tzdata_version, 0, tzdata_version.length); String magic = new String(tzdata_version, 0, 6, StandardCharsets.US_ASCII); if (!magic.equals("tzdata") || tzdata_version[11] != 0) { throw new RuntimeException("bad tzdata magic: " + Arrays.toString(tzdata_version)); } version = new String(tzdata_version, 6, 5, StandardCharsets.US_ASCII); int index_offset = it.readInt(); int data_offset = it.readInt(); int zonetab_offset = it.readInt(); readIndex(it, index_offset, data_offset); readZoneTab(it, zonetab_offset, (int) mappedFile.size() - zonetab_offset); }
public TimeZone makeTimeZone(String id) throws IOException { // Work out where in the big data file this time zone is. int index = Arrays.binarySearch(ids, id); if (index < 0) { return null; } BufferIterator it = mappedFile.bigEndianIterator(); it.skip(byteOffsets[index]); return ZoneInfo.makeTimeZone(id, it); } }
private boolean loadData(String path) { try { mappedFile = MemoryMappedFile.mmapRO(path); } catch (ErrnoException errnoException) { return false; } try { readHeader(); return true; } catch (Exception ex) { // Something's wrong with the file. // Log the problem and return false so we try the next choice. System.logE("tzdata file \"" + path + "\" was present but invalid!", ex); return false; } }
@Implementation public static MemoryMappedFile mmapRO(String path) throws Throwable { if (path.endsWith(TZ_DATA_1) || path.endsWith(TZ_DATA_2) || path.endsWith(TZ_DATA_3)) { InputStream is = MemoryMappedFile.class.getResourceAsStream(TZ_DATA_2); if (is == null) { throw (Throwable) exceptionClass().getConstructor(String.class, int.class) .newInstance("open", -1); } try { MemoryMappedFile memoryMappedFile = new MemoryMappedFile(0L, 0L); ShadowMemoryMappedFile shadowMemoryMappedFile = Shadow.extract(memoryMappedFile); shadowMemoryMappedFile.bytes = Streams.readFully(is); return memoryMappedFile; } catch (IOException e) { throw (Throwable) exceptionClass().getConstructor(String.class, int.class, Throwable.class) .newInstance("mmap", -1, e); } } else { throw new IllegalArgumentException("Unknown file for mmap: '" + path); } }
private void readHeader() { // byte[12] tzdata_version -- "tzdata2012f\0" // int index_offset // int data_offset // int zonetab_offset BufferIterator it = mappedFile.bigEndianIterator(); byte[] tzdata_version = new byte[12]; it.readByteArray(tzdata_version, 0, tzdata_version.length); String magic = new String(tzdata_version, 0, 6, StandardCharsets.US_ASCII); if (!magic.equals("tzdata") || tzdata_version[11] != 0) { throw new RuntimeException("bad tzdata magic: " + Arrays.toString(tzdata_version)); } version = new String(tzdata_version, 6, 5, StandardCharsets.US_ASCII); int index_offset = it.readInt(); int data_offset = it.readInt(); int zonetab_offset = it.readInt(); readIndex(it, index_offset, data_offset); readZoneTab(it, zonetab_offset, (int) mappedFile.size() - zonetab_offset); }
public TimeZone makeTimeZone(String id) throws IOException { // Work out where in the big data file this time zone is. int index = Arrays.binarySearch(ids, id); if (index < 0) { return null; } BufferIterator it = mappedFile.bigEndianIterator(); it.skip(byteOffsets[index]); return ZoneInfo.makeTimeZone(id, it); } }
private boolean loadData(String path) { try { mappedFile = MemoryMappedFile.mmapRO(path); } catch (ErrnoException errnoException) { return false; } try { readHeader(); return true; } catch (Exception ex) { // Something's wrong with the file. // Log the problem and return false so we try the next choice. System.logE("tzdata file \"" + path + "\" was present but invalid!", ex); return false; } }
@Implementation public static MemoryMappedFile mmapRO(String path) throws Throwable { if (path.endsWith(TZ_DATA_1) || path.endsWith(TZ_DATA_2) || path.endsWith(TZ_DATA_3)) { InputStream is = MemoryMappedFile.class.getResourceAsStream(TZ_DATA_2); if (is == null) { throw (Throwable) exceptionClass().getConstructor(String.class, int.class) .newInstance("open", -1); } try { MemoryMappedFile memoryMappedFile = new MemoryMappedFile(0L, 0L); ShadowMemoryMappedFile shadowMemoryMappedFile = Shadow.extract(memoryMappedFile); shadowMemoryMappedFile.bytes = Streams.readFully(is); return memoryMappedFile; } catch (IOException e) { throw (Throwable) exceptionClass().getConstructor(String.class, int.class, Throwable.class) .newInstance("mmap", -1, e); } } else { throw new IllegalArgumentException("Unknown file for mmap: '" + path); } }
private void readHeader() { // byte[12] tzdata_version -- "tzdata2012f\0" // int index_offset // int data_offset // int zonetab_offset BufferIterator it = mappedFile.bigEndianIterator(); byte[] tzdata_version = new byte[12]; it.readByteArray(tzdata_version, 0, tzdata_version.length); String magic = new String(tzdata_version, 0, 6, StandardCharsets.US_ASCII); if (!magic.equals("tzdata") || tzdata_version[11] != 0) { throw new RuntimeException("bad tzdata magic: " + Arrays.toString(tzdata_version)); } version = new String(tzdata_version, 6, 5, StandardCharsets.US_ASCII); int index_offset = it.readInt(); int data_offset = it.readInt(); int zonetab_offset = it.readInt(); readIndex(it, index_offset, data_offset); readZoneTab(it, zonetab_offset, (int) mappedFile.size() - zonetab_offset); }
public TimeZone makeTimeZone(String id) throws IOException { // Work out where in the big data file this time zone is. int index = Arrays.binarySearch(ids, id); if (index < 0) { return null; } BufferIterator it = mappedFile.bigEndianIterator(); it.skip(byteOffsets[index]); return ZoneInfo.makeTimeZone(id, it); } }