Java File Read by Charset getZipFile(File src, Charset charset)

Here you can find the source of getZipFile(File src, Charset charset)

Description

Returns a zipFile opened with a given charset

License

Apache License

Declaration

static ZipFile getZipFile(File src, Charset charset) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.IOException;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.util.zip.ZipFile;

public class Main {
    private static final String MISSING_METHOD_PLEASE_UPGRADE = "Your JRE doesn't support the ZipFile Charset constructor. Please upgrade JRE to 1.7 use this feature. Tried constructor ZipFile(File, Charset).";
    private static final String CONSTRUCTOR_MESSAGE_FOR_ZIPFILE = "Using constructor ZipFile(File, Charset) has failed: ";

    /**/* w  w w .  j  a  v a2 s  .  co m*/
     * Returns a zipFile opened with a given charset
     */
    static ZipFile getZipFile(File src, Charset charset) throws IOException {
        if (charset == null) {
            return new ZipFile(src);
        }

        try {
            Constructor<ZipFile> constructor = ZipFile.class
                    .getConstructor(new Class[] { File.class, Charset.class });
            return (ZipFile) constructor.newInstance(new Object[] { src, charset });
        } catch (NoSuchMethodException e) {
            throw new IllegalStateException(MISSING_METHOD_PLEASE_UPGRADE, e);
        } catch (InstantiationException e) {
            throw new IllegalStateException(CONSTRUCTOR_MESSAGE_FOR_ZIPFILE + e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(CONSTRUCTOR_MESSAGE_FOR_ZIPFILE + e.getMessage(), e);
        } catch (IllegalArgumentException e) {
            throw new IllegalStateException(CONSTRUCTOR_MESSAGE_FOR_ZIPFILE + e.getMessage(), e);
        } catch (InvocationTargetException e) {
            throw new IllegalStateException(CONSTRUCTOR_MESSAGE_FOR_ZIPFILE + e.getMessage(), e);
        }
    }
}

Related

  1. getNumberOfNonEmptyLines(File file, Charset charset)
  2. getPatchFileCharset()
  3. getPropertiesVaule(File file, String key, Charset charset)
  4. getString(File file, Charset charset)
  5. getUncommentedLines(File file, Charset forName)
  6. isEqual(final File document, final Charset a, final Charset b)
  7. load(File file, Charset charset)
  8. loadFile(File file, Charset cs)
  9. loadFile(File logfile, Charset charset)