Permalink
Browse files

Moved packages to be under com.integralblue.httpresponsecache

Depend on com.jakewharton.disklrucache to provide the disklrucache instead of bundling the source
Made more changes so everything compiles
Use maven as the build system
  • Loading branch information...
1 parent cb2231a commit 5373b019829eadefadd68032c94d68989793a9b6 Craig Andrews committed Jan 16, 2012
Showing with 967 additions and 1,902 deletions.
  1. +0 −8 .classpath
  2. +4 −0 .gitignore
  3. +0 −33 .project
  4. +0 −9 AndroidManifest.xml
  5. +115 −0 checkstyle.xml
  6. +127 −0 pom.xml
  7. 0 res/.keep
  8. +0 −9 src/com/integralblue/compat/Charsets.java
  9. +0 −7 src/com/integralblue/compat/Strings.java
  10. +0 −9 src/com/integralblue/compat/System.java
  11. +0 −199 src/com/integralblue/compat/libcore/io/BlockGuardOs.java
  12. +0 −804 src/com/integralblue/compat/libcore/io/DiskLruCache.java
  13. +0 −129 src/com/integralblue/compat/libcore/io/ForwardingOs.java
  14. +0 −67 src/com/integralblue/compat/libcore/io/GaiException.java
  15. +0 −151 src/com/integralblue/compat/libcore/io/IoUtils.java
  16. +0 −23 src/com/integralblue/compat/libcore/io/Libcore.java
  17. +0 −123 src/com/integralblue/compat/libcore/io/Os.java
  18. +0 −183 src/com/integralblue/compat/libcore/io/Posix.java
  19. +6 −10 ...ue/compat/android/net/http → main/java/com/integralblue/httpresponsecache}/HttpResponseCache.java
  20. +9 −0 src/main/java/com/integralblue/httpresponsecache/compat/Charsets.java
  21. +75 −0 src/main/java/com/integralblue/httpresponsecache/compat/Strings.java
  22. +11 −0 src/main/java/com/integralblue/httpresponsecache/compat/System.java
  23. +30 −0 src/main/java/com/integralblue/httpresponsecache/compat/URIs.java
  24. +28 −0 src/main/java/com/integralblue/httpresponsecache/compat/URLs.java
  25. +16 −0 src/main/java/com/integralblue/httpresponsecache/compat/java/io/IOException.java
  26. +1 −1 ...ain/java/com/integralblue/httpresponsecache}/compat/java/lang/ArrayIndexOutOfBoundsException.java
  27. +4 −2 ...gralblue → main/java/com/integralblue/httpresponsecache}/compat/java/lang/UnsafeByteSequence.java
  28. +16 −0 src/main/java/com/integralblue/httpresponsecache/compat/java/net/SocketException.java
  29. +2 −2 src/{com/integralblue → main/java/com/integralblue/httpresponsecache}/compat/java/util/Arrays.java
  30. +335 −0 src/main/java/com/integralblue/httpresponsecache/compat/java/util/concurrent/TimeUnit.java
  31. +5 −4 src/{com/integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/Base64.java
  32. +3 −4 ...ntegralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/ErrnoException.java
  33. +72 −0 src/main/java/com/integralblue/httpresponsecache/compat/libcore/io/IoUtils.java
  34. +1 −6 ...m/integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/OsConstants.java
  35. +2 −3 src/{com/integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/Streams.java
  36. +1 −1 ...ntegralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructAddrinfo.java
  37. +1 −1 ...m/integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructFlock.java
  38. +1 −1 ...ntegralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructGroupReq.java
  39. +1 −1 .../integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructLinger.java
  40. +1 −1 .../integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructPasswd.java
  41. +1 −1 .../integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructPollfd.java
  42. +1 −1 ...om/integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructStat.java
  43. +1 −1 .../integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructStatFs.java
  44. +1 −1 ...integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructTimeval.java
  45. +1 −1 ...integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/io/StructUtsname.java
  46. +2 −2 ...ain/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/AbstractHttpInputStream.java
  47. +1 −1 ...in/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/AbstractHttpOutputStream.java
  48. +3 −4 ...e → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/ChunkedInputStream.java
  49. +2 −3 ... → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/ChunkedOutputStream.java
  50. +2 −3 ...main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/FixedLengthInputStream.java
  51. +2 −3 ...ain/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/FixedLengthOutputStream.java
  52. +1 −1 ...ralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HeaderParser.java
  53. +19 −12 ...lblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpConnection.java
  54. +1 −16 ...e → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpConnectionPool.java
  55. +1 −1 ...ntegralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpDate.java
  56. +10 −9 ...egralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpEngine.java
  57. +1 −1 ...gralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpHandler.java
  58. +12 −12 ...ue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpResponseCache.java
  59. +8 −5 ... main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpURLConnectionImpl.java
  60. +1 −1 ...ralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpsHandler.java
  61. +4 −2 ...main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/HttpsURLConnectionImpl.java
  62. +4 −6 ...egralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/RawHeaders.java
  63. +2 −2 ...lblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/RequestHeaders.java
  64. +4 −5 ...blue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/ResponseHeaders.java
  65. +1 −1 ...lblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/ResponseSource.java
  66. +2 −3 ... main/java/com/integralblue/httpresponsecache}/compat/libcore/net/http/RetryableOutputStream.java
  67. +2 −3 ...ava/com/integralblue/httpresponsecache}/compat/libcore/net/http/UnknownLengthHttpInputStream.java
  68. +1 −1 .../integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/EmptyArray.java
  69. +1 −1 ...egralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/MutableBoolean.java
  70. +1 −1 ...integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/MutableByte.java
  71. +1 −1 ...integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/MutableChar.java
  72. +1 −1 ...tegralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/MutableDouble.java
  73. +1 −1 ...ntegralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/MutableFloat.java
  74. +1 −1 .../integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/MutableInt.java
  75. +1 −1 ...integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/MutableLong.java
  76. +1 −1 ...ntegralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/MutableShort.java
  77. +1 −1 ...com/integralblue → main/java/com/integralblue/httpresponsecache}/compat/libcore/util/Objects.java
View
8 .classpath
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
- <classpathentry kind="output" path="bin/classes"/>
-</classpath>
View
4 .gitignore
@@ -1,3 +1,7 @@
+.project
+.settings
+.classpath
gen
bin
+target
View
33 .project
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>HttpResponseCacheCompat</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.ApkBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
View
9 AndroidManifest.xml
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.integralblue.compat"
- android:versionCode="1"
- android:versionName="1.0" >
-
- <uses-sdk android:minSdkVersion="4" />
-
-</manifest>
View
115 checkstyle.xml
@@ -0,0 +1,115 @@
+<?xml version="1.0"?>
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
+ "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
+
+<module name="Checker">
+ <!--module name="NewlineAtEndOfFile"/-->
+ <module name="FileLength"/>
+ <module name="FileTabCharacter"/>
+
+ <!-- Trailing spaces -->
+ <module name="RegexpSingleline">
+ <property name="format" value="\s+$"/>
+ <property name="message" value="Line has trailing spaces."/>
+ </module>
+
+ <module name="TreeWalker">
+ <property name="cacheFile" value="${checkstyle.cache.file}"/>
+
+ <!-- Checks for Javadoc comments. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html -->
+ <!--module name="JavadocMethod"/-->
+ <!--module name="JavadocType"/-->
+ <!--module name="JavadocVariable"/-->
+ <!--module name="JavadocStyle"/-->
+
+
+ <!-- Checks for Naming Conventions. -->
+ <!-- See http://checkstyle.sf.net/config_naming.html -->
+ <!--module name="ConstantName"/-->
+ <!--module name="LocalFinalVariableName"/-->
+ <!--module name="LocalVariableName"/-->
+ <!--module name="MemberName"/-->
+ <!--module name="MethodName"/-->
+ <!--module name="PackageName"/-->
+ <!--module name="ParameterName"/-->
+ <!--module name="StaticVariableName"/-->
+ <!--module name="TypeName"/-->
+
+
+ <!-- Checks for imports -->
+ <!-- See http://checkstyle.sf.net/config_import.html -->
+ <module name="AvoidStarImport"/>
+ <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
+ <module name="RedundantImport"/>
+ <module name="UnusedImports"/>
+
+
+ <!-- Checks for Size Violations. -->
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
+ <!--module name="LineLength"/-->
+ <!--module name="MethodLength"/-->
+ <!--module name="ParameterNumber"/-->
+
+
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <!--module name="EmptyForIteratorPad"/-->
+ <!--module name="MethodParamPad"/-->
+ <!--module name="NoWhitespaceAfter"/-->
+ <!--module name="NoWhitespaceBefore"/-->
+ <!--module name="OperatorWrap"/-->
+ <!--module name="ParenPad"/-->
+ <!--module name="TypecastParenPad"/-->
+ <!--module name="WhitespaceAfter"/-->
+ <!--module name="WhitespaceAround"/-->
+
+
+ <!-- Modifier Checks -->
+ <!-- See http://checkstyle.sf.net/config_modifiers.html -->
+ <!--module name="ModifierOrder"/-->
+ <!--module name="RedundantModifier"/-->
+
+
+ <!-- Checks for blocks. You know, those {}'s -->
+ <!-- See http://checkstyle.sf.net/config_blocks.html -->
+ <!--module name="AvoidNestedBlocks"/-->
+ <!--module name="EmptyBlock"/-->
+ <!--module name="LeftCurly"/-->
+ <!--module name="NeedBraces"/-->
+ <!--module name="RightCurly"/-->
+
+
+ <!-- Checks for common coding problems -->
+ <!-- See http://checkstyle.sf.net/config_coding.html -->
+ <!--module name="AvoidInlineConditionals"/-->
+ <!--module name="DoubleCheckedLocking"/--> <!-- MY FAVOURITE -->
+ <!--module name="EmptyStatement"/-->
+ <!--module name="EqualsHashCode"/-->
+ <!--module name="HiddenField"/-->
+ <!--module name="IllegalInstantiation"/-->
+ <!--module name="InnerAssignment"/-->
+ <!--module name="MagicNumber"/-->
+ <!--module name="MissingSwitchDefault"/-->
+ <!--module name="RedundantThrows"/-->
+ <!--module name="SimplifyBooleanExpression"/-->
+ <!--module name="SimplifyBooleanReturn"/-->
+
+ <!-- Checks for class design -->
+ <!-- See http://checkstyle.sf.net/config_design.html -->
+ <!--module name="DesignForExtension"/-->
+ <!--module name="FinalClass"/-->
+ <!--module name="HideUtilityClassConstructor"/-->
+ <!--module name="InterfaceIsType"/-->
+ <!--module name="VisibilityModifier"/-->
+
+
+ <!-- Miscellaneous other checks. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
+ <!--module name="ArrayTypeStyle"/-->
+ <!--module name="FinalParameters"/-->
+ <!--module name="TodoComment"/-->
+ <!--module name="UpperEll"/-->
+ </module>
+</module>
View
127 pom.xml
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.sonatype.oss</groupId>
+ <artifactId>oss-parent</artifactId>
+ <version>7</version>
+ </parent>
+
+ <groupId>com.integralblue</groupId>
+ <artifactId>httpresponsecache</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0.0</version>
+
+ <name>HTTP Response Cache</name>
+ <description>An HTTP Response Cache for java.net.URL</description>
+ <url>https://gitorious.org/httpresponsecachecompat</url>
+ <inceptionYear>2012</inceptionYear>
+
+ <developers>
+ <developer>
+ <name>Craig Andrews</name>
+ <email>candrews@integralblue.com</email>
+ <id>candrews</id>
+ <url>http://candrews.integralblue.com.com</url>
+ <timezone>-5</timezone>
+ <roles>
+ <role>developer</role>
+ </roles>
+ </developer>
+ </developers>
+
+ <licenses>
+ <license>
+ <name>Apache License Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <url>https://gitorious.org/httpresponsecachecompat</url>
+ <connection>scm:git:git://gitorious.org/httpresponsecachecompat/main.git</connection>
+ <developerConnection>scm:git:git@gitorious.org:httpresponsecachecompat/main.git</developerConnection>
+ </scm>
+
+ <organization>
+ <name>Craig Andrews</name>
+ <url>http://candrews.integralblue.com</url>
+ </organization>
+
+ <properties>
+ <java.version>1.5</java.version>
+
+ <junit.version>4.8.2</junit.version>
+
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.jakewharton</groupId>
+ <artifactId>disklrucache</artifactId>
+ <version>1.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>${java.version}</source>
+ <target>${java.version}</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.2.2</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>2.8</version>
+ <configuration>
+ <failsOnError>true</failsOnError>
+ <configLocation>${project.basedir}/checkstyle.xml</configLocation>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>checkstyle</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-gitexe</artifactId>
+ <version>1.6</version>
+ </extension>
+ <extension>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-manager-plexus</artifactId>
+ <version>1.6</version>
+ </extension>
+ </extensions>
+ </build>
+</project>
+
View
0 res/.keep
No changes.
View
9 src/com/integralblue/compat/Charsets.java
@@ -1,9 +0,0 @@
-package com.integralblue.compat;
-
-import java.nio.charset.Charset;
-
-public class Charsets {
- public static final Charset UTF_8 = Charset.forName("UTF-8");
- public static final Charset US_ASCII = Charset.forName("US-ASCII");
- public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
-}
View
7 src/com/integralblue/compat/Strings.java
@@ -1,7 +0,0 @@
-package com.integralblue.compat;
-
-public final class Strings {
- public static final boolean isEmpty(String string){
- return string == null || string.length() == 0;
- }
-}
View
9 src/com/integralblue/compat/System.java
@@ -1,9 +0,0 @@
-package com.integralblue.compat;
-
-import android.util.Log;
-
-public final class System {
- public static final void logW(String msg){
- Log.w("System", msg);
- }
-}
View
199 src/com/integralblue/compat/libcore/io/BlockGuardOs.java
@@ -1,199 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.integralblue.compat.libcore.io;
-
-import dalvik.system.BlockGuard;
-import dalvik.system.SocketTagger;
-import java.io.FileDescriptor;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketException;
-import java.nio.ByteBuffer;
-
-import static com.integralblue.compat.libcore.io.OsConstants.*;
-
-/**
- * Informs BlockGuard of any activity it should be aware of.
- */
-public class BlockGuardOs extends ForwardingOs {
- public BlockGuardOs(Os os) {
- super(os);
- }
-
- private FileDescriptor tagSocket(FileDescriptor fd) throws ErrnoException {
- try {
- SocketTagger.get().tag(fd);
- return fd;
- } catch (SocketException e) {
- throw new ErrnoException("socket", EINVAL, e);
- }
- }
-
- private void untagSocket(FileDescriptor fd) throws ErrnoException {
- try {
- SocketTagger.get().untag(fd);
- } catch (SocketException e) {
- throw new ErrnoException("socket", EINVAL, e);
- }
- }
-
- @Override public FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException {
- BlockGuard.getThreadPolicy().onNetwork();
- return tagSocket(os.accept(fd, peerAddress));
- }
-
- @Override public void close(FileDescriptor fd) throws ErrnoException {
- try {
- if (S_ISSOCK(Libcore.os.fstat(fd).st_mode)) {
- if (isLingerSocket(fd)) {
- // If the fd is a socket with SO_LINGER set, we might block indefinitely.
- // We allow non-linger sockets so that apps can close their network
- // connections in methods like onDestroy which will run on the UI thread.
- BlockGuard.getThreadPolicy().onNetwork();
- }
- untagSocket(fd);
- }
- } catch (ErrnoException ignored) {
- // We're called via Socket.close (which doesn't ask for us to be called), so we
- // must not throw here, because Socket.close must not throw if asked to close an
- // already-closed socket. Also, the passed-in FileDescriptor isn't necessarily
- // a socket at all.
- }
- os.close(fd);
- }
-
- private static boolean isLingerSocket(FileDescriptor fd) throws ErrnoException {
- StructLinger linger = Libcore.os.getsockoptLinger(fd, SOL_SOCKET, SO_LINGER);
- return linger.isOn() && linger.l_linger > 0;
- }
-
- @Override public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException {
- BlockGuard.getThreadPolicy().onNetwork();
- os.connect(fd, address, port);
- }
-
- // TODO: Untag newFd when needed for dup2(FileDescriptor oldFd, int newFd)
-
- @Override public void fdatasync(FileDescriptor fd) throws ErrnoException {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- os.fdatasync(fd);
- }
-
- @Override public void fsync(FileDescriptor fd) throws ErrnoException {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- os.fsync(fd);
- }
-
- @Override public void ftruncate(FileDescriptor fd, long length) throws ErrnoException {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- os.ftruncate(fd, length);
- }
-
- @Override public FileDescriptor open(String path, int flags, int mode) throws ErrnoException {
- BlockGuard.getThreadPolicy().onReadFromDisk();
- if ((mode & O_ACCMODE) != O_RDONLY) {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- }
- return os.open(path, flags, mode);
- }
-
- @Override public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException {
- // Greater than 0 is a timeout in milliseconds and -1 means "block forever",
- // but 0 means "poll and return immediately", which shouldn't be subject to BlockGuard.
- if (timeoutMs != 0) {
- BlockGuard.getThreadPolicy().onNetwork();
- }
- return os.poll(fds, timeoutMs);
- }
-
- @Override public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException {
- BlockGuard.getThreadPolicy().onReadFromDisk();
- return os.pread(fd, buffer, offset);
- }
-
- @Override public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException {
- BlockGuard.getThreadPolicy().onReadFromDisk();
- return os.pread(fd, bytes, byteOffset, byteCount, offset);
- }
-
- @Override public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- return os.pwrite(fd, buffer, offset);
- }
-
- @Override public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- return os.pwrite(fd, bytes, byteOffset, byteCount, offset);
- }
-
- @Override public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException {
- BlockGuard.getThreadPolicy().onReadFromDisk();
- return os.read(fd, buffer);
- }
-
- @Override public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException {
- BlockGuard.getThreadPolicy().onReadFromDisk();
- return os.read(fd, bytes, byteOffset, byteCount);
- }
-
- @Override public int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException {
- BlockGuard.getThreadPolicy().onReadFromDisk();
- return os.readv(fd, buffers, offsets, byteCounts);
- }
-
- @Override public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException {
- BlockGuard.getThreadPolicy().onNetwork();
- return os.recvfrom(fd, buffer, flags, srcAddress);
- }
-
- @Override public int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException {
- BlockGuard.getThreadPolicy().onNetwork();
- return os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress);
- }
-
- @Override public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException {
- BlockGuard.getThreadPolicy().onNetwork();
- return os.sendto(fd, buffer, flags, inetAddress, port);
- }
-
- @Override public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException {
- // We permit datagrams without hostname lookups.
- if (inetAddress != null) {
- BlockGuard.getThreadPolicy().onNetwork();
- }
- return os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port);
- }
-
- @Override public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException {
- return tagSocket(os.socket(domain, type, protocol));
- }
-
- @Override public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- return os.write(fd, buffer);
- }
-
- @Override public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- return os.write(fd, bytes, byteOffset, byteCount);
- }
-
- @Override public int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException {
- BlockGuard.getThreadPolicy().onWriteToDisk();
- return os.writev(fd, buffers, offsets, byteCounts);
- }
-}
View
804 src/com/integralblue/compat/libcore/io/DiskLruCache.java
@@ -1,804 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.integralblue.compat.libcore.io;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedWriter;
-import java.io.Closeable;
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import com.integralblue.compat.Charsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * A cache that uses a bounded amount of space on a filesystem. Each cache
- * entry has a string key and a fixed number of values. Values are byte
- * sequences, accessible as streams or files. Each value must be between {@code
- * 0} and {@code Integer.MAX_VALUE} bytes in length.
- *
- * <p>The cache stores its data in a directory on the filesystem. This
- * directory must be exclusive to the cache; the cache may delete or overwrite
- * files from its directory. It is an error for multiple processes to use the
- * same cache directory at the same time.
- *
- * <p>This cache limits the number of bytes that it will store on the
- * filesystem. When the number of stored bytes exceeds the limit, the cache will
- * remove entries in the background until the limit is satisfied. The limit is
- * not strict: the cache may temporarily exceed it while waiting for files to be
- * deleted. The limit does not include filesystem overhead or the cache
- * journal so space-sensitive applications should set a conservative limit.
- *
- * <p>Clients call {@link #edit} to create or update the values of an entry. An
- * entry may have only one editor at one time; if a value is not available to be
- * edited then {@link #edit} will return null.
- * <ul>
- * <li>When an entry is being <strong>created</strong> it is necessary to
- * supply a full set of values; the empty value should be used as a
- * placeholder if necessary.
- * <li>When an entry is being <strong>created</strong>, it is not necessary
- * to supply data for every value; values default to their previous
- * value.
- * </ul>
- * Every {@link #edit} call must be matched by a call to {@link Editor#commit}
- * or {@link Editor#abort}. Committing is atomic: a read observes the full set
- * of values as they were before or after the commit, but never a mix of values.
- *
- * <p>Clients call {@link #get} to read a snapshot of an entry. The read will
- * observe the value at the time that {@link #get} was called. Updates and
- * removals after the call do not impact ongoing reads.
- *
- * <p>This class is tolerant of some I/O errors. If files are missing from the
- * filesystem, the corresponding entries will be dropped from the cache. If
- * an error occurs while writing a cache value, the edit will fail silently.
- * Callers should handle other problems by catching {@code IOException} and
- * responding appropriately.
- */
-public final class DiskLruCache implements Closeable {
- static final String JOURNAL_FILE = "journal";
- static final String JOURNAL_FILE_TMP = "journal.tmp";
- static final String MAGIC = "libcore.io.DiskLruCache";
- static final String VERSION_1 = "1";
- private static final String CLEAN = "CLEAN";
- private static final String DIRTY = "DIRTY";
- private static final String REMOVE = "REMOVE";
- private static final String READ = "READ";
-
- /*
- * This cache uses a journal file named "journal". A typical journal file
- * looks like this:
- * libcore.io.DiskLruCache
- * 1
- * 100
- * 2
- *
- * CLEAN 3400330d1dfc7f3f7f4b8d4d803dfcf6 832 21054
- * DIRTY 335c4c6028171cfddfbaae1a9c313c52
- * CLEAN 335c4c6028171cfddfbaae1a9c313c52 3934 2342
- * REMOVE 335c4c6028171cfddfbaae1a9c313c52
- * DIRTY 1ab96a171faeeee38496d8b330771a7a
- * CLEAN 1ab96a171faeeee38496d8b330771a7a 1600 234
- * READ 335c4c6028171cfddfbaae1a9c313c52
- * READ 3400330d1dfc7f3f7f4b8d4d803dfcf6
- *
- * The first five lines of the journal form its header. They are the
- * constant string "libcore.io.DiskLruCache", the disk cache's version,
- * the application's version, the value count, and a blank line.
- *
- * Each of the subsequent lines in the file is a record of the state of a
- * cache entry. Each line contains space-separated values: a state, a key,
- * and optional state-specific values.
- * o DIRTY lines track that an entry is actively being created or updated.
- * Every successful DIRTY action should be followed by a CLEAN or REMOVE
- * action. DIRTY lines without a matching CLEAN or REMOVE indicate that
- * temporary files may need to be deleted.
- * o CLEAN lines track a cache entry that has been successfully published
- * and may be read. A publish line is followed by the lengths of each of
- * its values.
- * o READ lines track accesses for LRU.
- * o REMOVE lines track entries that have been deleted.
- *
- * The journal file is appended to as cache operations occur. The journal may
- * occasionally be compacted by dropping redundant lines. A temporary file named
- * "journal.tmp" will be used during compaction; that file should be deleted if
- * it exists when the cache is opened.
- */
-
- private final File directory;
- private final File journalFile;
- private final File journalFileTmp;
- private final int appVersion;
- private final long maxSize;
- private final int valueCount;
- private long size = 0;
- private Writer journalWriter;
- private final LinkedHashMap<String, Entry> lruEntries
- = new LinkedHashMap<String, Entry>(0, 0.75f, true);
- private int redundantOpCount;
-
- /** This cache uses a single background thread to evict entries. */
- private final ExecutorService executorService = new ThreadPoolExecutor(0, 1,
- 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
- private final Callable<Void> cleanupCallable = new Callable<Void>() {
- @Override public Void call() throws Exception {
- synchronized (DiskLruCache.this) {
- if (journalWriter == null) {
- return null; // closed
- }
- trimToSize();
- if (journalRebuildRequired()) {
- rebuildJournal();
- redundantOpCount = 0;
- }
- }
- return null;
- }
- };
-
- private DiskLruCache(File directory, int appVersion, int valueCount, long maxSize) {
- this.directory = directory;
- this.appVersion = appVersion;
- this.journalFile = new File(directory, JOURNAL_FILE);
- this.journalFileTmp = new File(directory, JOURNAL_FILE_TMP);
- this.valueCount = valueCount;
- this.maxSize = maxSize;
- }
-
- /**
- * Opens the cache in {@code directory}, creating a cache if none exists
- * there.
- *
- * @param directory a writable directory
- * @param appVersion
- * @param valueCount the number of values per cache entry. Must be positive.
- * @param maxSize the maximum number of bytes this cache should use to store
- * @throws IOException if reading or writing the cache directory fails
- */
- public static DiskLruCache open(File directory, int appVersion, int valueCount, long maxSize)
- throws IOException {
- if (maxSize <= 0) {
- throw new IllegalArgumentException("maxSize <= 0");
- }
- if (valueCount <= 0) {
- throw new IllegalArgumentException("valueCount <= 0");
- }
-
- // prefer to pick up where we left off
- DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
- if (cache.journalFile.exists()) {
- try {
- cache.readJournal();
- cache.processJournal();
- cache.journalWriter = new BufferedWriter(new FileWriter(cache.journalFile, true));
- return cache;
- } catch (IOException journalIsCorrupt) {
- com.integralblue.compat.System.logW("DiskLruCache " + directory + " is corrupt: "
- + journalIsCorrupt.getMessage() + ", removing");
- cache.delete();
- }
- }
-
- // create a new empty cache
- directory.mkdirs();
- cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
- cache.rebuildJournal();
- return cache;
- }
-
- private void readJournal() throws IOException {
- InputStream in = new BufferedInputStream(new FileInputStream(journalFile));
- try {
- String magic = Streams.readAsciiLine(in);
- String version = Streams.readAsciiLine(in);
- String appVersionString = Streams.readAsciiLine(in);
- String valueCountString = Streams.readAsciiLine(in);
- String blank = Streams.readAsciiLine(in);
- if (!MAGIC.equals(magic)
- || !VERSION_1.equals(version)
- || !Integer.toString(appVersion).equals(appVersionString)
- || !Integer.toString(valueCount).equals(valueCountString)
- || !"".equals(blank)) {
- throw new IOException("unexpected journal header: ["
- + magic + ", " + version + ", " + valueCountString + ", " + blank + "]");
- }
-
- while (true) {
- try {
- readJournalLine(Streams.readAsciiLine(in));
- } catch (EOFException endOfJournal) {
- break;
- }
- }
- } finally {
- IoUtils.closeQuietly(in);
- }
- }
-
- private void readJournalLine(String line) throws IOException {
- String[] parts = line.split(" ");
- if (parts.length < 2) {
- throw new IOException("unexpected journal line: " + line);
- }
-
- String key = parts[1];
- if (parts[0].equals(REMOVE) && parts.length == 2) {
- lruEntries.remove(key);
- return;
- }
-
- Entry entry = lruEntries.get(key);
- if (entry == null) {
- entry = new Entry(key);
- lruEntries.put(key, entry);
- }
-
- if (parts[0].equals(CLEAN) && parts.length == 2 + valueCount) {
- entry.readable = true;
- entry.currentEditor = null;
- entry.setLengths(com.integralblue.compat.java.util.Arrays.copyOfRange(parts, 2, parts.length));
- } else if (parts[0].equals(DIRTY) && parts.length == 2) {
- entry.currentEditor = new Editor(entry);
- } else if (parts[0].equals(READ) && parts.length == 2) {
- // this work was already done by calling lruEntries.get()
- } else {
- throw new IOException("unexpected journal line: " + line);
- }
- }
-
- /**
- * Computes the initial size and collects garbage as a part of opening the
- * cache. Dirty entries are assumed to be inconsistent and will be deleted.
- */
- private void processJournal() throws IOException {
- deleteIfExists(journalFileTmp);
- for (Iterator<Entry> i = lruEntries.values().iterator(); i.hasNext(); ) {
- Entry entry = i.next();
- if (entry.currentEditor == null) {
- for (int t = 0; t < valueCount; t++) {
- size += entry.lengths[t];
- }
- } else {
- entry.currentEditor = null;
- for (int t = 0; t < valueCount; t++) {
- deleteIfExists(entry.getCleanFile(t));
- deleteIfExists(entry.getDirtyFile(t));
- }
- i.remove();
- }
- }
- }
-
- /**
- * Creates a new journal that omits redundant information. This replaces the
- * current journal if it exists.
- */
- private synchronized void rebuildJournal() throws IOException {
- if (journalWriter != null) {
- journalWriter.close();
- }
-
- Writer writer = new BufferedWriter(new FileWriter(journalFileTmp));
- writer.write(MAGIC);
- writer.write("\n");
- writer.write(VERSION_1);
- writer.write("\n");
- writer.write(Integer.toString(appVersion));
- writer.write("\n");
- writer.write(Integer.toString(valueCount));
- writer.write("\n");
- writer.write("\n");
-
- for (Entry entry : lruEntries.values()) {
- if (entry.currentEditor != null) {
- writer.write(DIRTY + ' ' + entry.key + '\n');
- } else {
- writer.write(CLEAN + ' ' + entry.key + entry.getLengths() + '\n');
- }
- }
-
- writer.close();
- journalFileTmp.renameTo(journalFile);
- journalWriter = new BufferedWriter(new FileWriter(journalFile, true));
- }
-
- private static void deleteIfExists(File file) throws IOException {
- try {
- Libcore.os.remove(file.getPath());
- } catch (ErrnoException errnoException) {
- if (errnoException.errno != OsConstants.ENOENT) {
- throw errnoException.rethrowAsIOException();
- }
- }
- }
-
- /**
- * Returns a snapshot of the entry named {@code key}, or null if it doesn't
- * exist is not currently readable. If a value is returned, it is moved to
- * the head of the LRU queue.
- */
- public synchronized Snapshot get(String key) throws IOException {
- checkNotClosed();
- validateKey(key);
- Entry entry = lruEntries.get(key);
- if (entry == null) {
- return null;
- }
-
- if (!entry.readable) {
- return null;
- }
-
- /*
- * Open all streams eagerly to guarantee that we see a single published
- * snapshot. If we opened streams lazily then the streams could come
- * from different edits.
- */
- InputStream[] ins = new InputStream[valueCount];
- try {
- for (int i = 0; i < valueCount; i++) {
- ins[i] = new FileInputStream(entry.getCleanFile(i));
- }
- } catch (FileNotFoundException e) {
- // a file must have been deleted manually!
- return null;
- }
-
- redundantOpCount++;
- journalWriter.append(READ + ' ' + key + '\n');
- if (journalRebuildRequired()) {
- executorService.submit(cleanupCallable);
- }
-
- return new Snapshot(ins);
- }
-
- /**
- * Returns an editor for the entry named {@code key}, or null if it cannot
- * currently be edited.
- */
- public synchronized Editor edit(String key) throws IOException {
- checkNotClosed();
- validateKey(key);
- Entry entry = lruEntries.get(key);
- if (entry == null) {
- entry = new Entry(key);
- lruEntries.put(key, entry);
- } else if (entry.currentEditor != null) {
- return null;
- }
-
- Editor editor = new Editor(entry);
- entry.currentEditor = editor;
-
- // flush the journal before creating files to prevent file leaks
- journalWriter.write(DIRTY + ' ' + key + '\n');
- journalWriter.flush();
- return editor;
- }
-
- /**
- * Returns the directory where this cache stores its data.
- */
- public File getDirectory() {
- return directory;
- }
-
- /**
- * Returns the maximum number of bytes that this cache should use to store
- * its data.
- */
- public long maxSize() {
- return maxSize;
- }
-
- /**
- * Returns the number of bytes currently being used to store the values in
- * this cache. This may be greater than the max size if a background
- * deletion is pending.
- */
- public synchronized long size() {
- return size;
- }
-
- private synchronized void completeEdit(Editor editor, boolean success) throws IOException {
- Entry entry = editor.entry;
- if (entry.currentEditor != editor) {
- throw new IllegalStateException();
- }
-
- // if this edit is creating the entry for the first time, every index must have a value
- if (success && !entry.readable) {
- for (int i = 0; i < valueCount; i++) {
- if (!entry.getDirtyFile(i).exists()) {
- editor.abort();
- throw new IllegalStateException("edit didn't create file " + i);
- }
- }
- }
-
- for (int i = 0; i < valueCount; i++) {
- File dirty = entry.getDirtyFile(i);
- if (success) {
- if (dirty.exists()) {
- File clean = entry.getCleanFile(i);
- dirty.renameTo(clean);
- long oldLength = entry.lengths[i];
- long newLength = clean.length();
- entry.lengths[i] = newLength;
- size = size - oldLength + newLength;
- }
- } else {
- deleteIfExists(dirty);
- }
- }
-
- redundantOpCount++;
- entry.currentEditor = null;
- if (entry.readable | success) {
- entry.readable = true;
- journalWriter.write(CLEAN + ' ' + entry.key + entry.getLengths() + '\n');
- } else {
- lruEntries.remove(entry.key);
- journalWriter.write(REMOVE + ' ' + entry.key + '\n');
- }
-
- if (size > maxSize || journalRebuildRequired()) {
- executorService.submit(cleanupCallable);
- }
- }
-
- /**
- * We only rebuild the journal when it will halve the size of the journal
- * and eliminate at least 2000 ops.
- */
- private boolean journalRebuildRequired() {
- final int REDUNDANT_OP_COMPACT_THRESHOLD = 2000;
- return redundantOpCount >= REDUNDANT_OP_COMPACT_THRESHOLD
- && redundantOpCount >= lruEntries.size();
- }
-
- /**
- * Drops the entry for {@code key} if it exists and can be removed. Entries
- * actively being edited cannot be removed.
- *
- * @return true if an entry was removed.
- */
- public synchronized boolean remove(String key) throws IOException {
- checkNotClosed();
- validateKey(key);
- Entry entry = lruEntries.get(key);
- if (entry == null || entry.currentEditor != null) {
- return false;
- }
-
- for (int i = 0; i < valueCount; i++) {
- File file = entry.getCleanFile(i);
- if (!file.delete()) {
- throw new IOException("failed to delete " + file);
- }
- size -= entry.lengths[i];
- entry.lengths[i] = 0;
- }
-
- redundantOpCount++;
- journalWriter.append(REMOVE + ' ' + key + '\n');
- lruEntries.remove(key);
-
- if (journalRebuildRequired()) {
- executorService.submit(cleanupCallable);
- }
-
- return true;
- }
-
- /**
- * Returns true if this cache has been closed.
- */
- public boolean isClosed() {
- return journalWriter == null;
- }
-
- private void checkNotClosed() {
- if (journalWriter == null) {
- throw new IllegalStateException("cache is closed");
- }
- }
-
- /**
- * Force buffered operations to the filesystem.
- */
- public synchronized void flush() throws IOException {
- checkNotClosed();
- trimToSize();
- journalWriter.flush();
- }
-
- /**
- * Closes this cache. Stored values will remain on the filesystem.
- */
- public synchronized void close() throws IOException {
- if (journalWriter == null) {
- return; // already closed
- }
- for (Entry entry : new ArrayList<Entry>(lruEntries.values())) {
- if (entry.currentEditor != null) {
- entry.currentEditor.abort();
- }
- }
- trimToSize();
- journalWriter.close();
- journalWriter = null;
- }
-
- private void trimToSize() throws IOException {
- while (size > maxSize) {
- Map.Entry<String, Entry> toEvict = lruEntries.eldest();
- remove(toEvict.getKey());
- }
- }
-
- /**
- * Closes the cache and deletes all of its stored values. This will delete
- * all files in the cache directory including files that weren't created by
- * the cache.
- */
- public void delete() throws IOException {
- close();
- IoUtils.deleteContents(directory);
- }
-
- private void validateKey(String key) {
- if (key.contains(" ") || key.contains("\n") || key.contains("\r")) {
- throw new IllegalArgumentException(
- "keys must not contain spaces or newlines: \"" + key + "\"");
- }
- }
-
- private static String inputStreamToString(InputStream in) throws IOException {
- return Streams.readFully(new InputStreamReader(in, Charsets.UTF_8));
- }
-
- /**
- * A snapshot of the values for an entry.
- */
- public static final class Snapshot implements Closeable {
- private final InputStream[] ins;
-
- private Snapshot(InputStream[] ins) {
- this.ins = ins;
- }
-
- /**
- * Returns the unbuffered stream with the value for {@code index}.
- */
- public InputStream getInputStream(int index) {
- return ins[index];
- }
-
- /**
- * Returns the string value for {@code index}.
- */
- public String getString(int index) throws IOException {
- return inputStreamToString(getInputStream(index));
- }
-
- @Override public void close() {
- for (InputStream in : ins) {
- IoUtils.closeQuietly(in);
- }
- }
- }
-
- /**
- * Edits the values for an entry.
- */
- public final class Editor {
- private final Entry entry;
- private boolean hasErrors;
-
- private Editor(Entry entry) {
- this.entry = entry;
- }
-
- /**
- * Returns an unbuffered input stream to read the last committed value,
- * or null if no value has been committed.
- */
- public InputStream newInputStream(int index) throws IOException {
- synchronized (DiskLruCache.this) {
- if (entry.currentEditor != this) {
- throw new IllegalStateException();
- }
- if (!entry.readable) {
- return null;
- }
- return new FileInputStream(entry.getCleanFile(index));
- }
- }
-
- /**
- * Returns the last committed value as a string, or null if no value
- * has been committed.
- */
- public String getString(int index) throws IOException {
- InputStream in = newInputStream(index);
- return in != null ? inputStreamToString(in) : null;
- }
-
- /**
- * Returns a new unbuffered output stream to write the value at
- * {@code index}. If the underlying output stream encounters errors
- * when writing to the filesystem, this edit will be aborted when
- * {@link #commit} is called. The returned output stream does not throw
- * IOExceptions.
- */
- public OutputStream newOutputStream(int index) throws IOException {
- synchronized (DiskLruCache.this) {
- if (entry.currentEditor != this) {
- throw new IllegalStateException();
- }
- return new FaultHidingOutputStream(new FileOutputStream(entry.getDirtyFile(index)));
- }
- }
-
- /**
- * Sets the value at {@code index} to {@code value}.
- */
- public void set(int index, String value) throws IOException {
- Writer writer = null;
- try {
- writer = new OutputStreamWriter(newOutputStream(index), Charsets.UTF_8);
- writer.write(value);
- } finally {
- IoUtils.closeQuietly(writer);
- }
- }
-
- /**
- * Commits this edit so it is visible to readers. This releases the
- * edit lock so another edit may be started on the same key.
- */
- public void commit() throws IOException {
- if (hasErrors) {
- completeEdit(this, false);
- remove(entry.key); // the previous entry is stale
- } else {
- completeEdit(this, true);
- }
- }
-
- /**
- * Aborts this edit. This releases the edit lock so another edit may be
- * started on the same key.
- */
- public void abort() throws IOException {
- completeEdit(this, false);
- }
-
- private class FaultHidingOutputStream extends FilterOutputStream {
- private FaultHidingOutputStream(OutputStream out) {
- super(out);
- }
-
- @Override public void write(int oneByte) {
- try {
- out.write(oneByte);
- } catch (IOException e) {
- hasErrors = true;
- }
- }
-
- @Override public void write(byte[] buffer, int offset, int length) {
- try {
- out.write(buffer, offset, length);
- } catch (IOException e) {
- hasErrors = true;
- }
- }
-
- @Override public void close() {
- try {
- out.close();
- } catch (IOException e) {
- hasErrors = true;
- }
- }
-
- @Override public void flush() {
- try {
- out.flush();
- } catch (IOException e) {
- hasErrors = true;
- }
- }
- }
- }
-
- private final class Entry {
- private final String key;
-
- /** Lengths of this entry's files. */
- private final long[] lengths;
-
- /** True if this entry has ever been published */
- private boolean readable;
-
- /** The ongoing edit or null if this entry is not being edited. */
- private Editor currentEditor;
-
- private Entry(String key) {
- this.key = key;
- this.lengths = new long[valueCount];
- }
-
- public String getLengths() throws IOException {
- StringBuilder result = new StringBuilder();
- for (long size : lengths) {
- result.append(' ').append(size);
- }
- return result.toString();
- }
-
- /**
- * Set lengths using decimal numbers like "10123".
- */
- private void setLengths(String[] strings) throws IOException {
- if (strings.length != valueCount) {
- throw invalidLengths(strings);
- }
-
- try {
- for (int i = 0; i < strings.length; i++) {
- lengths[i] = Long.parseLong(strings[i]);
- }
- } catch (NumberFormatException e) {
- throw invalidLengths(strings);
- }
- }
-
- private IOException invalidLengths(String[] strings) throws IOException {
- throw new IOException("unexpected journal line: " + Arrays.toString(strings));
- }
-
- public File getCleanFile(int i) {
- return new File(directory, key + "." + i);
- }
-
- public File getDirtyFile(int i) {
- return new File(directory, key + "." + i + ".tmp");
- }
- }
-}
View
129 src/com/integralblue/compat/libcore/io/ForwardingOs.java
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.integralblue.compat.libcore.io;
-
-import java.io.FileDescriptor;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-
-import com.integralblue.compat.libcore.util.MutableInt;
-import com.integralblue.compat.libcore.util.MutableLong;
-
-/**
- * Subclass this if you want to override some {@link Os} methods but otherwise delegate.
- */
-public class ForwardingOs implements Os {
- protected final Os os;
-
- public ForwardingOs(Os os) {
- this.os = os;
- }
-
- public FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException { return os.accept(fd, peerAddress); }
- public boolean access(String path, int mode) throws ErrnoException { return os.access(path, mode); }
- public void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException { os.bind(fd, address, port); }
- public void chmod(String path, int mode) throws ErrnoException { os.chmod(path, mode); }
- public void close(FileDescriptor fd) throws ErrnoException { os.close(fd); }
- public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException { os.connect(fd, address, port); }
- public FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return os.dup(oldFd); }
- public FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return os.dup2(oldFd, newFd); }
- public String[] environ() { return os.environ(); }
- public int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return os.fcntlVoid(fd, cmd); }
- public int fcntlLong(FileDescriptor fd, int cmd, long arg) throws ErrnoException { return os.fcntlLong(fd, cmd, arg); }
- public int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException { return os.fcntlFlock(fd, cmd, arg); }
- public void fdatasync(FileDescriptor fd) throws ErrnoException { os.fdatasync(fd); }
- public StructStat fstat(FileDescriptor fd) throws ErrnoException { return os.fstat(fd); }
- public StructStatFs fstatfs(FileDescriptor fd) throws ErrnoException { return os.fstatfs(fd); }
- public void fsync(FileDescriptor fd) throws ErrnoException { os.fsync(fd); }
- public void ftruncate(FileDescriptor fd, long length) throws ErrnoException { os.ftruncate(fd, length); }
- public String gai_strerror(int error) { return os.gai_strerror(error); }
- public InetAddress[] getaddrinfo(String node, StructAddrinfo hints) throws GaiException { return os.getaddrinfo(node, hints); }
- public int getegid() { return os.getegid(); }
- public int geteuid() { return os.geteuid(); }
- public int getgid() { return os.getgid(); }
- public String getenv(String name) { return os.getenv(name); }
- public String getnameinfo(InetAddress address, int flags) throws GaiException { return os.getnameinfo(address, flags); }
- public int getpid() { return os.getpid(); }
- public int getppid() { return os.getppid(); }
- public StructPasswd getpwnam(String name) throws ErrnoException { return os.getpwnam(name); }
- public StructPasswd getpwuid(int uid) throws ErrnoException { return os.getpwuid(uid); }
- public SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return os.getsockname(fd); }
- public int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptByte(fd, level, option); }
- public InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptInAddr(fd, level, option); }
- public int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptInt(fd, level, option); }
- public StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptLinger(fd, level, option); }
- public StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptTimeval(fd, level, option); }
- public int getuid() { return os.getuid(); }
- public String if_indextoname(int index) { return os.if_indextoname(index); }
- public InetAddress inet_pton(int family, String address) { return os.inet_pton(family, address); }
- public InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return os.ioctlInetAddress(fd, cmd, interfaceName); }
- public int ioctlInt(FileDescriptor fd, int cmd, MutableInt arg) throws ErrnoException { return os.ioctlInt(fd, cmd, arg); }
- public boolean isatty(FileDescriptor fd) { return os.isatty(fd); }
- public void kill(int pid, int signal) throws ErrnoException { os.kill(pid, signal); }
- public void listen(FileDescriptor fd, int backlog) throws ErrnoException { os.listen(fd, backlog); }
- public long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return os.lseek(fd, offset, whence); }
- public StructStat lstat(String path) throws ErrnoException { return os.lstat(path); }
- public void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { os.mincore(address, byteCount, vector); }
- public void mkdir(String path, int mode) throws ErrnoException { os.mkdir(path, mode); }
- public void mlock(long address, long byteCount) throws ErrnoException { os.mlock(address, byteCount); }
- public long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException { return os.mmap(address, byteCount, prot, flags, fd, offset); }
- public void msync(long address, long byteCount, int flags) throws ErrnoException { os.msync(address, byteCount, flags); }
- public void munlock(long address, long byteCount) throws ErrnoException { os.munlock(address, byteCount); }
- public void munmap(long address, long byteCount) throws ErrnoException { os.munmap(address, byteCount); }
- public FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return os.open(path, flags, mode); }
- public FileDescriptor[] pipe() throws ErrnoException { return os.pipe(); }
- public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return os.poll(fds, timeoutMs); }
- public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException { return os.pread(fd, buffer, offset); }
- public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException { return os.pread(fd, bytes, byteOffset, byteCount, offset); }
- public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException { return os.pwrite(fd, buffer, offset); }
- public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException { return os.pwrite(fd, bytes, byteOffset, byteCount, offset); }
- public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException { return os.read(fd, buffer); }
- public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException { return os.read(fd, bytes, byteOffset, byteCount); }
- public int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException { return os.readv(fd, buffers, offsets, byteCounts); }
- public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException { return os.recvfrom(fd, buffer, flags, srcAddress); }
- public int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException { return os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress); }
- public void remove(String path) throws ErrnoException { os.remove(path); }
- public void rename(String oldPath, String newPath) throws ErrnoException { os.rename(oldPath, newPath); }
- public long sendfile(FileDescriptor outFd, FileDescriptor inFd, MutableLong inOffset, long byteCount) throws ErrnoException { return os.sendfile(outFd, inFd, inOffset, byteCount); }
- public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException { return os.sendto(fd, buffer, flags, inetAddress, port); }
- public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException { return os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port); }
- public void setegid(int egid) throws ErrnoException { os.setegid(egid); }
- public void seteuid(int euid) throws ErrnoException { os.seteuid(euid); }
- public void setgid(int gid) throws ErrnoException { os.setgid(gid); }
- public void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptByte(fd, level, option, value); }
- public void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { os.setsockoptIfreq(fd, level, option, value); }
- public void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptInt(fd, level, option, value); }
- public void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptIpMreqn(fd, level, option, value); }
- public void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { os.setsockoptGroupReq(fd, level, option, value); }
- public void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException { os.setsockoptLinger(fd, level, option, value); }
- public void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException { os.setsockoptTimeval(fd, level, option, value); }
- public void setuid(int uid) throws ErrnoException { os.setuid(uid); }
- public void shutdown(FileDescriptor fd, int how) throws ErrnoException { os.shutdown(fd, how); }
- public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return os.socket(domain, type, protocol); }
- public StructStat stat(String path) throws ErrnoException { return os.stat(path); }
- public StructStatFs statfs(String path) throws ErrnoException { return os.statfs(path); }
- public String strerror(int errno) { return os.strerror(errno); }
- public void symlink(String oldPath, String newPath) throws ErrnoException { os.symlink(oldPath, newPath); }
- public long sysconf(int name) { return os.sysconf(name); }
- public StructUtsname uname() { return os.uname(); }
- public int waitpid(int pid, MutableInt status, int options) throws ErrnoException { return os.waitpid(pid, status, options); }
- public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException { return os.write(fd, buffer); }
- public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException { return os.write(fd, bytes, byteOffset, byteCount); }
- public int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException { return os.writev(fd, buffers, offsets, byteCounts); }
-}
View
67 src/com/integralblue/compat/libcore/io/GaiException.java
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.integralblue.compat.libcore.io;
-
-import java.net.UnknownHostException;
-
-import com.integralblue.compat.libcore.io.OsConstants;
-
-/**
- * An unchecked exception thrown when the {@link Os} {@code getaddrinfo} or {@code getnameinfo}
- * methods fail. This exception contains the native error value, for comparison against the
- * {@code GAI_} constants in {@link OsConstants}, should sophisticated
- * callers need to adjust their behavior based on the exact failure.
- */
-public final class GaiException extends RuntimeException {
- private final String functionName;
- public final int error;
-
- public GaiException(String functionName, int error) {
- this.functionName = functionName;
- this.error = error;
- }
-
- public GaiException(String functionName, int error, Throwable cause) {
- super(cause);
- this.functionName = functionName;
- this.error = error;
- }
-
- /**
- * Converts the stashed function name and error value to a human-readable string.
- * We do this here rather than in the constructor so that callers only pay for
- * this if they need it.
- */
- @Override public String getMessage() {
- String gaiName = OsConstants.gaiName(error);
- if (gaiName == null) {
- gaiName = "GAI_ error " + error;
- }
- String description = Libcore.os.gai_strerror(error);
- return functionName + " failed: " + gaiName + " (" + description + ")";
- }
-
- public UnknownHostException rethrowAsUnknownHostException(String detailMessage) throws UnknownHostException {
- UnknownHostException newException = new UnknownHostException(detailMessage);
- newException.initCause(this);
- throw newException;
- }
-
- public UnknownHostException rethrowAsUnknownHostException() throws UnknownHostException {
- throw rethrowAsUnknownHostException(getMessage());
- }
-}
View
151 src/com/integralblue/compat/libcore/io/IoUtils.java
@@ -1,151 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.integralblue.compat.libcore.io;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.net.Socket;
-import com.integralblue.compat.Charsets;
-import com.integralblue.compat.java.lang.UnsafeByteSequence;
-
-import static com.integralblue.compat.libcore.io.OsConstants.*;
-
-public final class IoUtils {
- private IoUtils() {
- }
-
- /**
- * Calls close(2) on 'fd'. Also resets the internal int to -1. Does nothing if 'fd' is null
- * or invalid.
- */
- public static void close(FileDescriptor fd) throws IOException {
- try {
- if (fd != null && fd.valid()) {
- Libcore.os.close(fd);
- }
- } catch (ErrnoException errnoException) {
- throw errnoException.rethrowAsIOException();
- }
- }
-
- /**
- * Closes 'closeable', ignoring any checked exceptions. Does nothing if 'closeable' is null.
- */
- public static void closeQuietly(Closeable closeable) {
- if (closeable != null) {
- try {
- closeable.close();
- } catch (RuntimeException rethrown) {
- throw rethrown;
- } catch (Exception ignored) {
- }
- }
- }
-
- /**
- * 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) {
- }
- }
-
- /**
- * Closes 'socket', ignoring any exceptions. Does nothing if 'socket' is null.
- */
- public static void closeQuietly(Socket socket) {
- if (socket != null) {
- try {
- socket.close();
- } catch (Exception ignored) {
- }
- }
- }
-
- /**
- * Sets 'fd' to be blocking or non-blocking, according to the state of 'blocking'.
- */
- public static void setBlocking(FileDescriptor fd, boolean blocking) throws IOException {
- try {
- int flags = Libcore.os.fcntlVoid(fd, F_GETFL);
- if (!blocking) {
- flags |= O_NONBLOCK;
- } else {
- flags &= ~O_NONBLOCK;
- }
- Libcore.os.fcntlLong(fd, F_SETFL, flags);
- } catch (ErrnoException errnoException) {
- throw errnoException.rethrowAsIOException();
- }
- }
-
- /**
- * Returns the contents of 'path' as a byte array.
- */
- public static byte[] readFileAsByteArray(String path) throws IOException {
- return readFileAsBytes(path).toByteArray();
- }
-
- /**
- * Returns the contents of 'path' as a string. The contents are assumed to be UTF-8.
- */
- public static String readFileAsString(String path) throws IOException {
- return readFileAsBytes(path).toString(Charsets.UTF_8);
- }
-
- private static UnsafeByteSequence readFileAsBytes(String path) throws IOException {
- RandomAccessFile f = null;
- try {
- f = new RandomAccessFile(path, "r");
- UnsafeByteSequence bytes = new UnsafeByteSequence((int) f.length());
- byte[] buffer = new byte[8192];
- while (true) {
- int byteCount = f.read(buffer);
- if (byteCount == -1) {
- return bytes;
- }
- bytes.write(buffer, 0, byteCount);
- }
- } finally {
- IoUtils.closeQuietly(f);
- }
- }
-
- /**
- * Recursively delete everything in {@code dir}.
- */
- // TODO: this should specify paths as Strings rather than as Files
- public static void deleteContents(File dir) throws IOException {
- File[] files = dir.listFiles();
- if (files == null) {
- throw new IllegalArgumentException("not a directory: " + dir);
- }
- for (File file : files) {
- if (file.isDirectory()) {
- deleteContents(file);
- }
- if (!file.delete()) {
- throw new IOException("failed to delete file: " + file);
- }
- }
- }
-}
View
23 src/com/integralblue/compat/libcore/io/Libcore.java
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.integralblue.compat.libcore.io;
-
-public final class Libcore {
- private Libcore() { }
-
- public static Os os = new BlockGuardOs(new Posix());
-}
View
123 src/com/integralblue/compat/libcore/io/Os.java
@@ -1,123 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.integralblue.compat.libcore.io;
-
-import java.io.FileDescriptor;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-
-import com.integralblue.compat.libcore.util.MutableInt;
-import com.integralblue.compat.libcore.util.MutableLong;
-
-public interface Os {
- public FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException;
- public boolean access(String path, int mode) throws ErrnoException;
- public void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException;
- public void chmod(String path, int mode) throws ErrnoException;
- public void close(FileDescriptor fd) throws ErrnoException;
- public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException;
- public FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException;
- public FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException;
- public String[] environ();
- public int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException;
- public int fcntlLong(FileDescriptor fd, int cmd, long arg) throws ErrnoException;
- public int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException;
- public void fdatasync(FileDescriptor fd) throws ErrnoException;
- public StructStat fstat(FileDescriptor fd) throws ErrnoException;
- public StructStatFs fstatfs(FileDescriptor fd) throws ErrnoException;
- public void fsync(FileDescriptor fd) throws ErrnoException;
- public void ftruncate(FileDescriptor fd, long length) throws ErrnoException;
- public String gai_strerror(int error);
- public InetAddress[] getaddrinfo(String node, StructAddrinfo hints) throws GaiException;
- public int getegid();
- public int geteuid();
- public int getgid();
- public String getenv(String name);
- /* TODO: break into getnameinfoHost and getnameinfoService? */
- public String getnameinfo(InetAddress address, int flags) throws GaiException;
- public int getpid();
- public int getppid();
- public StructPasswd getpwnam(String name) throws ErrnoException;
- public StructPasswd getpwuid(int uid) throws ErrnoException;
- public SocketAddress getsockname(FileDescriptor fd) throws ErrnoException;
- public int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException;
- public InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException;
- public int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException;
- public StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException;
- public StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException;
- public int getuid();
- public String if_indextoname(int index);
- public InetAddress inet_pton(int family, String address);
- public InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException;
- public int ioctlInt(FileDescriptor fd, int cmd, MutableInt arg) throws ErrnoException;
- public boolean isatty(FileDescriptor fd);
- public void kill(int pid, int signal) throws ErrnoException;
- public void listen(FileDescriptor fd, int backlog) throws ErrnoException;
- public long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException;
- public StructStat lstat(String path) throws ErrnoException;
- public void mincore(long address, long byteCount, byte[] vector) throws ErrnoException;
- public void mkdir(String path, int mode) throws ErrnoException;
- public void mlock(long address, long byteCount) throws ErrnoException;
- public long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException;
- public void msync(long address, long byteCount, int flags) throws ErrnoException;
- public void munlock(long address, long byteCount) throws ErrnoException;
- public void munmap(long address, long byteCount) throws ErrnoException;
- public FileDescriptor open(String path, int flags, int mode) throws ErrnoException;
- public FileDescriptor[] pipe() throws ErrnoException;
- /* TODO: if we used the non-standard ppoll(2) behind the scenes, we could take a long timeout. */
- public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException;
- public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException;
- public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException;
- public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException;
- public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException;
- public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException;
- public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException;
- public int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException;
- public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException;
- public int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException;
- public void remove(String path) throws ErrnoException;
- public void rename(String oldPath, String newPath) throws ErrnoException;
- public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException;
- public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException;
- public long sendfile(FileDescriptor outFd, FileDescriptor inFd, MutableLong inOffset, long byteCount) throws ErrnoException;
- public void setegid(int egid) throws ErrnoException;
- public void seteuid(int euid) throws ErrnoException;
- public void setgid(int gid) throws ErrnoException;
- public void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException;
- public void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException;
- public void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException;
- public void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException;
- public void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException;
- public void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException;
- public void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException;
- public void setuid(int uid) throws ErrnoException;
- public void shutdown(FileDescriptor fd, int how) throws ErrnoException;
- public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException;
- public StructStat stat(String path) throws ErrnoException;
- /* TODO: replace statfs with statvfs. */
- public StructStatFs statfs(String path) throws ErrnoException;
- public String strerror(int errno);
- public void symlink(String oldPath, String newPath) throws ErrnoException;
- public long sysconf(int name);
- public StructUtsname uname();
- public int waitpid(int pid, MutableInt status, int options) throws ErrnoException;
- public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException;
- public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException;
- public int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException;
-}
View
183 src/com/integralblue/compat/libcore/io/Posix.java
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.integralblue.compat.libcore.io;
-
-import java.io.FileDescriptor;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.NioUtils;
-
-import com.integralblue.compat.libcore.util.MutableInt;
-import com.integralblue.compat.libcore.util.MutableLong;
-
-public final class Posix implements Os {
- Posix() { }
-
- public native FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException;
- public native boolean access(String path, int mode) throws ErrnoException;
- public native void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException;
- public native void chmod(String path, int mode) throws ErrnoException;
- public native void close(FileDescriptor fd) throws ErrnoException;
- public native void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException;
- public native FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException;
- public native FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException;
- public native String[] environ();
- public native int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException;
- public native int fcntlLong(FileDescriptor fd, int cmd, long arg) throws ErrnoException;
- public native int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException;
- public native void fdatasync(FileDescriptor fd) throws ErrnoException;
- public native StructStat fstat(FileDescriptor fd) throws ErrnoException;
- public native StructStatFs fstatfs(FileDescriptor fd) throws ErrnoException;
- public native void fsync(FileDescriptor fd) throws ErrnoException;
- public native void ftruncate(FileDescriptor fd, long length) throws ErrnoException;
- public native String gai_strerror(int error);
- public native InetAddress[] getaddrinfo(String node, StructAddrinfo hints) throws GaiException;
- public native int getegid();
- public native int geteuid();
- public native int getgid();
- public native String getenv(String name);
- public native String getnameinfo(InetAddress address, int flags) throws GaiException;
- public native int getpid();
- public native int getppid();
- public native StructPasswd getpwnam(String name) throws ErrnoException;
- public native StructPasswd getpwuid(int uid) throws ErrnoException;
- public native SocketAddress getsockname(FileDescriptor fd) throws ErrnoException;
- public native int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException;
- public native InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException;
- public native int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException;
- public native StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException;
- public native StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException;
- public native int getuid();
- public native String if_indextoname(int index);
- public native InetAddress inet_pton(int family, String address);
- public native InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException;
- public native int ioctlInt(FileDescriptor fd, int cmd, MutableInt arg) throws ErrnoException;
- public native boolean isatty(FileDescriptor fd);
- public native void kill(int pid, int signal) throws ErrnoException;
- public native void listen(FileDescriptor fd, int backlog) throws ErrnoException;
- public native long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException;
- public native StructStat lstat(String path) throws ErrnoException;
- public native void mincore(long address, long byteCount, byte[] vector) throws ErrnoException;
- public native void mkdir(String path, int mode) throws ErrnoException;
- public native void mlock(long address, long byteCount) throws ErrnoException;
- public native long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException;
- public native void msync(long address, long byteCount, int flags) throws ErrnoException;
- public native void munlock(long address, long byteCount) throws ErrnoException;
- public native void munmap(long address, long byteCount) throws ErrnoException;
- public native FileDescriptor open(String path, int flags, int mode) throws ErrnoException;
- public native FileDescriptor[] pipe() throws ErrnoException;
- public native int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException;
- public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException {
- if (buffer.isDirect()) {
- return preadBytes(fd, buffer, buffer.position(), buffer.remaining(), offset);
- } else {
- return preadBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining(), offset);
- }
- }
- public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException {
- // This indirection isn't strictly necessary, but ensures that our public interface is type safe.
- return preadBytes(fd, bytes, byteOffset, byteCount, offset);
- }
- private native int preadBytes(FileDescriptor fd, Object buffer, int bufferOffset, int byteCount, long offset) throws ErrnoException;
- public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException {
- if (buffer.isDirect()) {
- return pwriteBytes(fd, buffer, buffer.position(), buffer.remaining(), offset);
- } else {
- return pwriteBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining(), offset);
- }
- }
- public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException {
- // This indirection isn't strictly necessary, but ensures that our public interface is type safe.
- return pwriteBytes(fd, bytes, byteOffset, byteCount, offset);
- }
- private native int pwriteBytes(FileDescriptor fd, Object buffer, int bufferOffset, int byteCount, long offset) throws ErrnoException;
- public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException {
- if (buffer.isDirect()) {
- return readBytes(fd, buffer, buffer.position(), buffer.remaining());
- } else {
- return readBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining());
- }
- }
- public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException {
- // This indirection isn't strictly necessary, but ensures that our public interface is type safe.
- return readBytes(fd, bytes, byteOffset, byteCount);
- }
- private native int readBytes(FileDescriptor fd, Object buffer, int offset, int byteCount) throws ErrnoException;
- public native int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException;
- public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException {
- if (buffer.isDirect()) {
- return recvfromBytes(fd, buffer, buffer.position(), buffer.remaining(), flags, srcAddress);
- } else {
- return recvfromBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining(), flags, srcAddress);
- }
- }
- public int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException {
- // This indirection isn't strictly necessary, but ensures that our public interface is type safe.
- return recvfromBytes(fd, bytes, byteOffset, byteCount, flags, srcAddress);
- }
- private native int recvfromBytes(FileDescriptor fd, Object buffer, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException;
- public native void remove(String path) throws ErrnoException;
- public native void rename(String oldPath, String newPath) throws ErrnoException;
- public native long sendfile(FileDescriptor outFd, FileDescriptor inFd, MutableLong inOffset, long byteCount) throws ErrnoException;
- public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException {
- if (buffer.isDirect()) {
- return sendtoBytes(fd, buffer, buffer.position(), buffer.remaining(), flags, inetAddress, port);
- } else {
- return sendtoBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining(), flags, inetAddress, port);
- }
- }
- public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException {
- // This indirection isn't strictly necessary, but ensures that our public interface is type safe.
- return sendtoBytes(fd, bytes, byteOffset, byteCount, flags, inetAddress, port);
- }
- private native int sendtoBytes(FileDescriptor fd, Object buffer, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException;
- public native void setegid(int egid) throws ErrnoException;
- public native void seteuid(int euid) throws ErrnoException;
- public native void setgid(int gid) throws ErrnoException;
- public native void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException;
- public native void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException;
- public native void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException;
- public native void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException;
- public native void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException;
- public native void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException;
- public native void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException;
- public native void setuid(int uid) throws ErrnoException;
- public native void shutdown(FileDescriptor fd, int how) throws ErrnoException;
- public native FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException;
- public native StructStat stat(String path) throws ErrnoException;
- public native StructStatFs statfs(String path) throws ErrnoException;
- public native String strerror(int errno);
- public native void symlink(String oldPath, String newPath) throws ErrnoException;
- public native long sysconf(int name);
- public native StructUtsname uname();
- public native int waitpid(int pid, MutableInt status, int options) throws ErrnoException;
- public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException {
- if (buffer.isDirect()) {
- return writeBytes(fd, buffer, buffer.position(), buffer.remaining());
- } else {
- return writeBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining());
- }
- }
- public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException {
- // This indirection isn't strictly necessary, but ensures that our public interface is type safe.
- return writeBytes(fd, bytes, byteOffset, byteCount);
- }
- private native int writeBytes(FileDescriptor fd, Object buffer, int offset, int byteCount) throws ErrnoException;
- public native int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException;
-}
View
16 ...t/android/net/http/HttpResponseCache.java → .../httpresponsecache/HttpResponseCache.java