android.os.DropBoxManager#IS_EMPTY源码实例Demo

下面列出了android.os.DropBoxManager#IS_EMPTY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: DropBoxManagerService.java
/**
 * 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);
}
 
源代码2 项目: android_9.0.0_r45   文件: DropBoxManagerService.java
/**
 * Creates a EntryFile object with only a timestamp for comparison purposes.
 * @param millis to compare with.
 */
public EntryFile(long millis) {
    this.tag = null;
    this.timestampMillis = millis;
    this.flags = DropBoxManager.IS_EMPTY;
    this.blocks = 0;
}
 
源代码3 项目: android_9.0.0_r45   文件: DropBoxManagerService.java
/** @return File extension for the flags. */
private String getExtension() {
    if ((flags &  DropBoxManager.IS_EMPTY) != 0) {
        return ".lost";
    }
    return ((flags & DropBoxManager.IS_TEXT) != 0 ? ".txt" : ".dat") +
            ((flags & DropBoxManager.IS_GZIPPED) != 0 ? ".gz" : "");
}
 
源代码4 项目: android_9.0.0_r45   文件: DropBoxManagerService.java
/**
 * 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;
}
 
源代码5 项目: android_9.0.0_r45   文件: DropBoxManagerService.java
/** Moves a temporary file to a final log filename and enrolls it. */
private synchronized long createEntry(File temp, String tag, int flags) throws IOException {
    long t = System.currentTimeMillis();

    // Require each entry to have a unique timestamp; if there are entries
    // >10sec in the future (due to clock skew), drag them back to avoid
    // keeping them around forever.

    SortedSet<EntryFile> tail = mAllFiles.contents.tailSet(new EntryFile(t + 10000));
    EntryFile[] future = null;
    if (!tail.isEmpty()) {
        future = tail.toArray(new EntryFile[tail.size()]);
        tail.clear();  // Remove from mAllFiles
    }

    if (!mAllFiles.contents.isEmpty()) {
        t = Math.max(t, mAllFiles.contents.last().timestampMillis + 1);
    }

    if (future != null) {
        for (EntryFile late : future) {
            mAllFiles.blocks -= late.blocks;
            FileList tagFiles = mFilesByTag.get(late.tag);
            if (tagFiles != null && tagFiles.contents.remove(late)) {
                tagFiles.blocks -= late.blocks;
            }
            if ((late.flags & DropBoxManager.IS_EMPTY) == 0) {
                enrollEntry(new EntryFile(late.getFile(mDropBoxDir), mDropBoxDir,
                        late.tag, t++, late.flags, mBlockSize));
            } else {
                enrollEntry(new EntryFile(mDropBoxDir, late.tag, t++));
            }
        }
    }

    if (temp == null) {
        enrollEntry(new EntryFile(mDropBoxDir, tag, t));
    } else {
        enrollEntry(new EntryFile(temp, mDropBoxDir, tag, t, flags, mBlockSize));
    }
    return t;
}
 
源代码6 项目: android_9.0.0_r45   文件: DropBoxManagerService.java
/**
 * 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();
}
 
 方法所在类
 同类方法