Java Code Examples for android.text.TextUtils#safeIntern()

The following examples show how to use android.text.TextUtils#safeIntern() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Moves an existing temporary file to a new log filename.
 *
 * @param temp file to rename
 * @param dir to store file in
 * @param tag to use for new log file name
 * @param timestampMillis of log entry
 * @param flags for the entry data
 * @param blockSize to use for space accounting
 * @throws IOException if the file can't be moved
 */
public EntryFile(File temp, File dir, String tag,long timestampMillis,
                 int flags, int blockSize) throws IOException {
    if ((flags & DropBoxManager.IS_EMPTY) != 0) throw new IllegalArgumentException();

    this.tag = TextUtils.safeIntern(tag);
    this.timestampMillis = timestampMillis;
    this.flags = flags;

    final File file = this.getFile(dir);
    if (!temp.renameTo(file)) {
        throw new IOException("Can't rename " + temp + " to " + file);
    }
    this.blocks = (int) ((file.length() + blockSize - 1) / blockSize);
}
 
Example 2
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts metadata from an existing on-disk log filename.
 *
 * Note when a filename is not recognizable, it will create an instance that
 * {@link #hasFile()} would return false on, and also remove the file.
 *
 * @param file name of existing log file
 * @param blockSize to use for space accounting
 */
public EntryFile(File file, int blockSize) {

    boolean parseFailure = false;

    String name = file.getName();
    int flags = 0;
    String tag = null;
    long millis = 0;

    final int at = name.lastIndexOf('@');
    if (at < 0) {
        parseFailure = true;
    } else {
        tag = Uri.decode(name.substring(0, at));
        if (name.endsWith(".gz")) {
            flags |= DropBoxManager.IS_GZIPPED;
            name = name.substring(0, name.length() - 3);
        }
        if (name.endsWith(".lost")) {
            flags |= DropBoxManager.IS_EMPTY;
            name = name.substring(at + 1, name.length() - 5);
        } else if (name.endsWith(".txt")) {
            flags |= DropBoxManager.IS_TEXT;
            name = name.substring(at + 1, name.length() - 4);
        } else if (name.endsWith(".dat")) {
            name = name.substring(at + 1, name.length() - 4);
        } else {
            parseFailure = true;
        }
        if (!parseFailure) {
            try {
                millis = Long.parseLong(name);
            } catch (NumberFormatException e) {
                parseFailure = true;
            }
        }
    }
    if (parseFailure) {
        Slog.wtf(TAG, "Invalid filename: " + file);

        // Remove the file and return an empty instance.
        file.delete();
        this.tag = null;
        this.flags = DropBoxManager.IS_EMPTY;
        this.timestampMillis = 0;
        this.blocks = 0;
        return;
    }

    this.blocks = (int) ((file.length() + blockSize - 1) / blockSize);
    this.tag = TextUtils.safeIntern(tag);
    this.flags = flags;
    this.timestampMillis = millis;
}
 
Example 3
Source File: DropBoxManagerService.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a zero-length tombstone for a file whose contents were lost.
 *
 * @param dir to store file in
 * @param tag to use for new log file name
 * @param timestampMillis of log entry
 * @throws IOException if the file can't be created.
 */
public EntryFile(File dir, String tag, long timestampMillis) throws IOException {
    this.tag = TextUtils.safeIntern(tag);
    this.timestampMillis = timestampMillis;
    this.flags = DropBoxManager.IS_EMPTY;
    this.blocks = 0;
    new FileOutputStream(getFile(dir)).close();
}