Package org.nutz.resource.impl

Source Code of org.nutz.resource.impl.JarEntryResource

package org.nutz.resource.impl;

import java.io.IOException;
import java.io.InputStream;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.nutz.resource.JarEntryInfo;
import org.nutz.resource.NutResource;

/**
* 封装了 jar 内的 Entity
*
* @author zozoh(zozohtnt@gmail.com)
*/
public class JarEntryResource extends NutResource {

  private JarFile jar;

  private JarEntry entry;

  public JarEntryResource(JarEntryInfo jeInfo) throws IOException {
    this.jar = new JarFile(jeInfo.getJarPath());
    this.entry = jar.getJarEntry(jeInfo.getEntryName());
    if (null == this.entry)
      throw new IOException("Invalid JarEntry :" + jeInfo);
    this.name = jeInfo.getEntryName();
  }

  public JarEntryResource(JarFile jar, JarEntry jen, String name) {
    this.jar = jar;
    this.entry = jen;
    this.name = name;
  }

  public JarFile getJar() {
    return jar;
  }

  public JarEntry getEntry() {
    return entry;
  }

  @Override
  public InputStream getInputStream() throws IOException {
    return jar.getInputStream(entry);
  }

}
TOP

Related Classes of org.nutz.resource.impl.JarEntryResource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.