Android Open Source - tazDownloader Taz File






From Project

Back to project page tazDownloader.

License

The source code is released under:

GNU General Public License

If you think the Android project tazDownloader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright (c) 2012 Olaf Sebelin.//from   w  w w.j av  a 2s .c  om
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package read.taz;

import java.io.File;
import java.net.URI;
import java.util.Calendar;
import java.util.Date;

import android.util.Log;

public class TazFile {
  public static enum FileType {
    /** PDF with all pages. */
    PDF("taz_", ".pdf", "application/pdf"),
    /** EPUB with facsimile pictures. */
    EPUB("taz_", ".epub", "application/epub+zip"),
    /** EPUB without facsimile pictures. */
    EPUB_TEXT_ONLY("tazt_", ".epub", "application/epub+zip");

    public final String filenamePrefix;
    public final String filenameSuffix;
    public final String mimeType;

    private FileType(String filenamePrefix, String filenameSuffix,
        String _mimetype) {
      this.filenamePrefix = filenamePrefix;
      this.filenameSuffix = filenameSuffix;
      mimeType = _mimetype;
    }

    /**
     * Strip the filename from pre- and suffix
     */
    public String stripFilename(String filename) {
      return filename.substring(filenamePrefix.length(), filename.length()
          - filenameSuffix.length());
    }

    public boolean matches(String filename) {
      return filename.startsWith(filenamePrefix)
          && filename.endsWith(filenameSuffix);
    }
  };

  public final FileType type;

  public final Calendar date;

  public final File file;

  TazFile(FileType type, Calendar date, File file) {
    super();
    this.type = type;
    this.date = date;
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    this.file = file;
  }

  public URI getDownloadURI() {
    return URI.create("http://dl.taz.de/taz/abo/get.php?f=" + file.getName());
  }

  @Override
  public String toString() {
    return file.getAbsolutePath();
  }

  public void deleteIfOlderThan(Date that) {
    if (date.getTime().before(that)) {
      Log.d("deleteIfOlderThan", "Deleting " + file.getName()
          + " since it is older than " + that);
      if (!file.delete()) {
        Log.w(getClass().getSimpleName(), "Cannot delete " + file);
      }
    }
  }
}




Java Source Code List

read.taz.AbstractTazReaderMainActivity.java
read.taz.CleanupService.java
read.taz.DownloadActivity.java
read.taz.SettingsActivity.java
read.taz.ShowOnStartup.java
read.taz.TazDownloadListener.java
read.taz.TazDownloadService.java
read.taz.TazDownloader.java
read.taz.TazFileFactory.java
read.taz.TazFile.java
read.taz.TazReaderActivity.java