Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package meids.

db; import import import import import import import import import java.io.BufferedReader; java.io.File; java.io.FileInputStream; java.io.IOException; java.io.InputStreamReader; java.util.Vector; java.util.logging.Level; java.util.logging.Logger; org.jdesktop.application.Application;

/** * * @author Student */ public class DBUtils { public static String[] getPatterns() { BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new FileInputStrea m(new File(Application.getInstance().getContext().getLocalStorage().getDirectory ().getAbsolutePath() + File.separatorChar + "Patterns" + File.separatorChar + "p atterns.db")))); String line = reader.readLine(); Vector<String> patterns = new Vector<String>(); while (line != null) { //String binaryString = toBinaryString(line); patterns.add(line); line = reader.readLine(); } String[] patterns1 = new String[patterns.size()]; return patterns.toArray(patterns1); } catch (IOException ex) { Logger.getLogger(DBUtils.class.getName()).log(Level.SEVERE, null, ex ); } finally { try { reader.close(); } catch (IOException ex) { Logger.getLogger(DBUtils.class.getName()).log(Level.SEVERE, null , ex); } } return new String[0]; } private static String toBinaryString(String pattern) { byte[] pattern1 = pattern.getBytes(); String binaryString = ""; for(byte b : pattern1) {

for(int i=0;i<8;i++) { binaryString += "" + ((b & (byte) Math.pow(2, i))==(byte) Math.p ow(2, i)?"1":"0"); } } return binaryString; } }

You might also like