Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    private static boolean debug;

    public static String readChannelString(String path, String prefixString) {
        String ret = null;
        ZipFile zipfile = null;
        try {
            zipfile = new ZipFile(path);
            Enumeration<?> entries = zipfile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = ((ZipEntry) entries.nextElement());
                String entryName = entry.getName();
                if (debug) {
                    System.out.println(entryName);
                }
                if (entryName.contains(prefixString)) {
                    ret = entryName;

                    break;
                }
            }

            if (ret != null) {
                String[] split = ret.split("_");
                if (split != null && split.length >= 2) {
                    String substring = ret.substring(split[0].length() + 1);
                    if (debug) {
                        System.out.println(String.format("find channel string:%s", substring));
                    }
                    return substring;

                }
            } else {
                if (debug) {
                    System.out.println("not find channel");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (zipfile != null) {
                try {
                    zipfile.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return ret;

    }
}