-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated DiskLruCache to jw/1.2.0, closes #17
- Loading branch information
Showing
7 changed files
with
123 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.handlerexploit.common.utils; | ||
|
||
import java.lang.reflect.Array; | ||
|
||
/* From java.util.Arrays */ | ||
class Arrays { | ||
@SuppressWarnings("unchecked") | ||
public static <T> T[] copyOfRange(T[] original, int start, int end) { | ||
int originalLength = original.length; // For exception priority compatibility. | ||
if (start > end) { | ||
throw new IllegalArgumentException(); | ||
} | ||
if (start < 0 || start > originalLength) { | ||
throw new ArrayIndexOutOfBoundsException(); | ||
} | ||
int resultLength = end - start; | ||
int copyLength = Math.min(resultLength, originalLength - start); | ||
T[] result = (T[]) Array.newInstance(original.getClass().getComponentType(), resultLength); | ||
System.arraycopy(original, start, result, 0, copyLength); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.handlerexploit.common.utils; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
/** From java.nio.charset.Charsets */ | ||
class Charsets { | ||
static final Charset US_ASCII = Charset.forName("US-ASCII"); | ||
static final Charset UTF_8 = Charset.forName("UTF-8"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.handlerexploit.common.utils; | ||
|
||
import java.io.Closeable; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** From libcore.io.IoUtils */ | ||
class IoUtils { | ||
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); | ||
} | ||
} | ||
} | ||
|
||
static void closeQuietly(/*Auto*/Closeable closeable) { | ||
if (closeable != null) { | ||
try { | ||
closeable.close(); | ||
} catch (RuntimeException rethrown) { | ||
throw rethrown; | ||
} catch (Exception ignored) { | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.handlerexploit.common.utils; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.io.StringWriter; | ||
|
||
/** From libcore.io.Streams */ | ||
class Streams { | ||
static String readFully(Reader reader) throws IOException { | ||
try { | ||
StringWriter writer = new StringWriter(); | ||
char[] buffer = new char[1024]; | ||
int count; | ||
while ((count = reader.read(buffer)) != -1) { | ||
writer.write(buffer, 0, count); | ||
} | ||
return writer.toString(); | ||
} finally { | ||
reader.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters