Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import android.os.Build;

public class Main {
    static boolean isTheUpdateForMe(File path) {

        JarFile jar;
        try {
            jar = new JarFile(path);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            return false;
        }

        ZipEntry entry = jar.getEntry("system/build.prop");
        final String myDevice = "ro.product.device=" + Build.DEVICE;
        boolean finded = false;

        if (entry != null) {
            try {
                InputStreamReader bi = new InputStreamReader(jar.getInputStream(entry));

                BufferedReader br = new BufferedReader(bi);

                String line;
                Pattern p = Pattern.compile(myDevice);
                do {
                    line = br.readLine();
                    if (line == null) {
                        break;
                    }

                    Matcher m = p.matcher(line);
                    if (m.find()) {
                        finded = true;
                        break;
                    }
                } while (true);

                bi.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }
        }
        try {
            jar.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return finded;
    }
}