Esempio n. 1
0
  // TODO: normalize to /paths/ and ban retard \paths\; make it a method of Utils.
  public InputStream getInputStream(String from, String what) throws IOException {
    ZipFile zipFile;

    try {
      zipFile = new ZipFile(from);
    } catch (IOException e) {
      throw new IOException("Failed to open " + from, e);
    }

    /* The API borks if we use a leading '/', so take care of it */
    String p = what.startsWith("/") ? what.substring(1) : what;

    ZipEntry zipEntry = zipFile.getEntry(p);
    if (zipEntry == null) {
      throw new IOException("Zip file " + from + " doesn't contain " + p);
    }

    if (zipEntry.isDirectory()) {
      Log.w(TAG, "We can't use a directory inside a zip file as a resource!");
    }

    InputStream is;
    try {
      is = zipFile.getInputStream(zipEntry);
      /* Instead of one of the documentation exceptions we might just get
       * null in some cases. So we need to test this, as <b>we</b>
       * promise to throw IOException rather than return null!
       */
      if (is == null) {
        throw new IOException("ZipFile#getInputStream returned null!");
      }
    } catch (IOException e) {
      throw new IOException("Failed to load resource", e);
    }

    return is;
  }
Esempio n. 2
0
 public Player() {
   Log.i(TAG, "Player object created.");
 }