@Override public void close() { IoUtils.closeQuietly(is); IoUtils.closeQuietly(controlSocket); }
/** * Do not use. Use createTemporaryDirectory instead. * * Used by frameworks/base unit tests to clean up a temporary directory. * Deliberately ignores errors, on the assumption that test cleanup is only * supposed to be best-effort. * * @deprecated Use {@link #createTemporaryDirectory} instead. */ public static void deleteContents(File dir) throws IOException { File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { deleteContents(file); } file.delete(); } } }
public String getZoneTab() { if (zoneTab == null) { try { zoneTab = IoUtils.readFileAsString(ZONE_DIRECTORY_NAME + "zone.tab"); } catch (IOException e) { throw new Error(e); } } return zoneTab; }
/** * Closes 'fd', ignoring any exceptions. Does nothing if 'fd' is null or invalid. */ public static void closeQuietly(FileDescriptor fd) { try { IoUtils.close(fd); } catch (IOException ignored) { } }
/** * Reads the file indicating the database version in use. */ private static String readVersion() { // Mac OS X / iOS have a +VERSION file in /usr/share/zoneinfo containing the version number try { byte[] bytes = IoUtils.readFileAsByteArray(ZONE_DIRECTORY_NAME + "+VERSION"); return new String(bytes, 0, bytes.length, StandardCharsets.ISO_8859_1).trim(); } catch (IOException ex) { // Linux (at least Ubuntu) doesn't have a +VERSION file. Just return unknown. return "unknown"; } }
@Override protected void implConfigureBlocking(boolean blocking) throws IOException { IoUtils.setBlocking(fd, blocking); }
candidates.add(candidate); if (IoUtils.canOpenReadOnly(candidate)) { try {
@Override public void close() throws IOException { try { super.close(); } finally { synchronized (this) { try { IoUtils.close(fd); } finally { fd = null; } } } } }
private TimeZone makeTimeZone(String id, boolean clone) throws IOException { // Check the aliases first String realId = deprecatedAliases.get(id); if (realId != null) { return makeTimeZone(realId, clone); } // Work out where in the big data file this time zone is. int index = Arrays.binarySearch(ids, id); if (index < 0) { return null; } ZoneInfo zoneInfo = zoneInfos[index]; if (zoneInfo != null) { return clone ? (TimeZone) zoneInfo.clone() : zoneInfo; } byte[] bytes = IoUtils.readFileAsByteArray(ZONE_DIRECTORY_NAME + id); BufferIterator it = HeapBufferIterator.iterator(bytes, 0, bytes.length, ByteOrder.BIG_ENDIAN); zoneInfo = (ZoneInfo) ZoneInfo.makeTimeZone(id, it); zoneInfos[index] = zoneInfo; return clone ? (TimeZone) zoneInfo.clone() : zoneInfo; }
@Override protected void implConfigureBlocking(boolean blocking) throws IOException { IoUtils.setBlocking(fd, blocking); }
candidates.add(candidate); if (IoUtils.canOpenReadOnly(candidate)) { try {
public void destroy() { // If the process hasn't already exited, send it SIGKILL. synchronized (exitValueMutex) { if (exitValue == null) { try { Libcore.os.kill(pid, SIGKILL); } catch (ErrnoException e) { System.logI("Failed to destroy process " + pid, e); } } } // Close any open streams. IoUtils.closeQuietly(inputStream); IoUtils.closeQuietly(errorStream); IoUtils.closeQuietly(outputStream); }
try { zoneName = IoUtils.readFileAsString("/etc/timezone").trim(); } catch (IOException e) {
@Override public void close() throws IOException { try { super.close(); } finally { synchronized (this) { try { IoUtils.close(fd); } finally { fd = null; } } } } }
/** * Reads the file indicating the database version in use. */ private static String readVersion() { // Mac OS X / iOS have a +VERSION file in /usr/share/zoneinfo containing the version number try { byte[] bytes = IoUtils.readFileAsByteArray(ZONE_DIRECTORY_NAME + "+VERSION"); return new String(bytes, 0, bytes.length, StandardCharsets.ISO_8859_1).trim(); } catch (IOException ex) { // Linux (at least Ubuntu) doesn't have a +VERSION file. Just return unknown. return "unknown"; } }
@Override protected void implConfigureBlocking(boolean blocking) throws IOException { IoUtils.setBlocking(getFD(), blocking); }
/** * Do not use. Use createTemporaryDirectory instead. * * Used by frameworks/base unit tests to clean up a temporary directory. * Deliberately ignores errors, on the assumption that test cleanup is only * supposed to be best-effort. * * @deprecated Use {@link #createTemporaryDirectory} instead. */ public static void deleteContents(File dir) throws IOException { File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { deleteContents(file); } file.delete(); } } }