Java Properties Load from File loadJZ(File file)

Here you can find the source of loadJZ(File file)

Description

load JZ

License

Open Source License

Declaration

public static Properties loadJZ(File file) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayInputStream;
import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;
import java.io.IOException;

import java.util.Properties;

public class Main {
    public static Properties loadJZ(File file) {
        Properties props = new Properties();
        if (file.exists()) {
            try {
                FileReader reader = new FileReader(file);
                char[] buf = new char[1024];
                StringBuffer buffer = new StringBuffer();
                int read = 0;
                boolean isStarted = false;
                while ((read = reader.read(buf)) != -1) {
                    buffer.append(buf, 0, read);
                    if (buffer.length() > 10) {
                        if (buffer.toString().startsWith("/*=j2s=")) {
                            isStarted = true;
                        } else {/* w  w w  .  j a va2  s. c o  m*/
                            return props;
                        }
                    }
                    if (isStarted) {
                        if (buffer.indexOf("=*/") != -1) {
                            break;
                        }
                    }
                }
                reader.close();
                if (isStarted) {
                    String str = buffer.toString();
                    int idx1 = str.indexOf('\n', 7);
                    if (idx1 != -1) {
                        int idx2 = str.indexOf("=*/", idx1);
                        if (idx2 != -1) {
                            str = str.substring(idx1 + 1, idx2);
                            props.load(new ByteArrayInputStream(str.getBytes()));
                        }
                    }
                }
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return props;
    }
}

Related

  1. loadGradleResource(String fileName)
  2. loadHeader(String fileName)
  3. loadIncludes(String propertyName, boolean mandatory, File file, Properties configProps)
  4. loadInputAsString(InputStream is)
  5. loadInstallProps()
  6. loadKeys(String propertiesFileName, InputStream in)
  7. loadLibrary(String libFileName)
  8. loadLibrarySmart(String libraryName)
  9. loadLocalization(final ZipFile file, final String loc)