Example usage for java.util Scanner hasNextLine

List of usage examples for java.util Scanner hasNextLine

Introduction

In this page you can find the example usage for java.util Scanner hasNextLine.

Prototype

public boolean hasNextLine() 

Source Link

Document

Returns true if there is another line in the input of this scanner.

Usage

From source file:azkaban.jobtype.ReportalHiveRunner.java

@Override
protected void runReportal() throws Exception {
    System.out.println("Reportal Hive: Setting up Hive");
    HiveConf conf = new HiveConf(SessionState.class);

    if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) {
        conf.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION"));
    }/*  w  w  w .j  a  va 2 s  .c om*/

    File tempTSVFile = new File("./temp.tsv");
    OutputStream tsvTempOutputStream = new BoundedOutputStream(
            new BufferedOutputStream(new FileOutputStream(tempTSVFile)), outputCapacity);
    PrintStream logOut = System.out;

    // NOTE: It is critical to do this here so that log4j is reinitialized
    // before any of the other core hive classes are loaded
    // criccomini@linkedin.com: I disabled this because it appears to swallow
    // all future logging (even outside of hive).
    // SessionState.initHiveLog4j();

    String orig = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS);

    CliSessionState sessionState = new CliSessionState(conf);
    sessionState.in = System.in;
    sessionState.out = new PrintStream(tsvTempOutputStream, true, "UTF-8");
    sessionState.err = new PrintStream(logOut, true, "UTF-8");

    OptionsProcessor oproc = new OptionsProcessor();

    // Feed in Hive Args
    String[] args = buildHiveArgs();
    if (!oproc.process_stage1(args)) {
        throw new Exception("unable to parse options stage 1");
    }

    if (!oproc.process_stage2(sessionState)) {
        throw new Exception("unable to parse options stage 2");
    }

    // Set all properties specified via command line
    for (Map.Entry<Object, Object> item : sessionState.cmdProperties.entrySet()) {
        conf.set((String) item.getKey(), (String) item.getValue());
    }

    SessionState.start(sessionState);

    String expanded = expandHiveAuxJarsPath(orig);
    if (orig == null || orig.equals(expanded)) {
        System.out.println("Hive aux jars variable not expanded");
    } else {
        System.out.println("Expanded aux jars variable from [" + orig + "] to [" + expanded + "]");
        HiveConf.setVar(conf, HiveConf.ConfVars.HIVEAUXJARS, expanded);
    }

    if (!ShimLoader.getHadoopShims().usesJobShell()) {
        // hadoop-20 and above - we need to augment classpath using hiveconf
        // components
        // see also: code in ExecDriver.java
        ClassLoader loader = conf.getClassLoader();
        String auxJars = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS);

        System.out.println("Got auxJars = " + auxJars);

        if (StringUtils.isNotBlank(auxJars)) {
            loader = Utilities.addToClassPath(loader, StringUtils.split(auxJars, ","));
        }
        conf.setClassLoader(loader);
        Thread.currentThread().setContextClassLoader(loader);
    }

    CliDriver cli = new CliDriver();
    int returnValue = 0;
    String prefix = "";

    returnValue = cli.processLine("set hive.cli.print.header=true;");
    String[] queries = jobQuery.split("\n");
    for (String line : queries) {
        if (!prefix.isEmpty()) {
            prefix += '\n';
        }
        if (line.trim().endsWith(";") && !line.trim().endsWith("\\;")) {
            line = prefix + line;
            line = injectVariables(line);
            System.out.println("Reportal Hive: Running Hive Query: " + line);
            System.out.println("Reportal Hive: HiveConf HIVEAUXJARS: "
                    + HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS));
            returnValue = cli.processLine(line);
            prefix = "";
        } else {
            prefix = prefix + line;
            continue;
        }
    }

    tsvTempOutputStream.close();

    // convert tsv to csv and write it do disk
    System.out.println("Reportal Hive: Converting output");
    InputStream tsvTempInputStream = new BufferedInputStream(new FileInputStream(tempTSVFile));
    Scanner rowScanner = new Scanner(tsvTempInputStream);
    PrintStream csvOutputStream = new PrintStream(outputStream);
    while (rowScanner.hasNextLine()) {
        String tsvLine = rowScanner.nextLine();
        // strip all quotes, and then quote the columns
        csvOutputStream.println("\"" + tsvLine.replace("\"", "").replace("\t", "\",\"") + "\"");
    }
    rowScanner.close();
    csvOutputStream.close();

    // Flush the temp file out
    tempTSVFile.delete();

    if (returnValue != 0) {
        throw new Exception("Hive query finished with a non zero return code");
    }

    System.out.println("Reportal Hive: Ended successfully");
}

From source file:org.mskcc.cbio.cgds.scripts.drug.internal.PiHelperImporter.java

private void importDrugTargets() throws Exception {
    Scanner scanner = new Scanner(getDrugTargetsFile());
    DaoGeneOptimized daoGeneOptimized = DaoGeneOptimized.getInstance();
    DaoDrugInteraction daoDrugInteraction = DaoDrugInteraction.getInstance();

    int lineNo = 0, saved = 0;
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (line.startsWith("#"))
            continue;
        if ((++lineNo) == 1)
            continue;

        String[] tokens = line.split(separator);
        assert tokens.length == 5;
        if (tokens.length < 5)
            continue;
        /*//from  w  ww.ja  v  a 2s  .c  o  m
        0 - PiHelperId
        1 - Symbol
        2 - Drug
        3 - DataSources
        4 - References
         */

        String geneSymbol = tokens[1].trim();
        String drugName = tokens[2].trim();
        String datasources = tokens[3].trim();
        String refs = tokens[4].trim();

        Drug drug = nameToDrugMap.get(drugName);
        assert drug != null;

        if (drug == DRUG_SKIP)
            continue;

        List<CanonicalGene> genes = daoGeneOptimized.guessGene(geneSymbol);
        for (CanonicalGene gene : genes) {
            daoDrugInteraction.addDrugInteraction(drug, gene, DRUG_INTERACTION_TYPE, datasources, "", refs);
            saved++;
        }
    }

    scanner.close();

    log.info("Number of drug-targets imported: " + saved);
}

From source file:com.inaetics.demonstrator.MainActivity.java

/**
 * Method called when QR-code scanner has been triggered and finished.
 * If a qr-code is scanned it will process the content.
 *///from   w  ww .  j a v a  2s . c o  m
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null) {
        if (result.getContents() == null) {
            Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
        } else {
            String content = result.getContents();
            try {
                new URL(content);
                // Is a url!
                download(content);
            } catch (MalformedURLException e) {
                //Not an url
                Scanner sc = new Scanner(content);
                boolean autostart = false;
                while (sc.hasNextLine()) {
                    String[] keyValue = sc.nextLine().split("=");
                    switch (keyValue[0]) {
                    case "cosgi.auto.start.1":
                        autostart = true;
                        String startBundles = "";
                        Scanner bscan = new Scanner(keyValue[1]);
                        while (bscan.hasNext()) {
                            startBundles += model.getBundleLocation() + "/" + bscan.next() + " ";
                        }
                        bscan.close();
                        config.putProperty(keyValue[0], startBundles);
                        break;
                    case "deployment_admin_identification":
                        config.putProperty(keyValue[0], keyValue[1] + "_" + model.getCpu_abi());
                        break;
                    default:
                        try {
                            config.putProperty(keyValue[0], keyValue[1]);
                        } catch (ArrayIndexOutOfBoundsException ex) {
                            //Ignore property there is no key/value combination
                            Log.e("Scanner", "couldn't scan: " + Arrays.toString(keyValue));
                        }
                    }
                }
                sc.close();
                if (autostart && !Celix.getInstance().isCelixRunning()) {
                    Celix.getInstance().startFramework(config.getConfigPath());
                }
                Toast.makeText(this, "Scanned QR", Toast.LENGTH_SHORT).show();
            }

        }
    }
}

From source file:com.ibm.iotf.sample.devicemgmt.device.RasPiFirmwareHandlerSample.java

private InstalStatus ParseInstallLog() throws FileNotFoundException {
    try {/*  w w w  .j  ava2 s.  c  o  m*/
        File file = new File(INSTALL_LOG_FILE);
        Scanner scanner = new Scanner(file);

        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.contains(DEPENDENCY_ERROR_MSG)) {
                scanner.close();
                return InstalStatus.DEPENDENCY_ERROR;
            } else if (line.contains(ERROR_MSG)) {
                scanner.close();
                return InstalStatus.ERROR;
            }
        }
        scanner.close();
    } catch (FileNotFoundException e) {
        throw e;
    }
    return InstalStatus.SUCCESS;
}

From source file:com.joliciel.talismane.fr.TalismaneFrench.java

@Override
public TransitionSystem getDefaultTransitionSystem() {
    TransitionSystem transitionSystem = this.getParserService().getArcEagerTransitionSystem();
    InputStream inputStream = getInputStreamFromResource("talismaneDependencyLabels.txt");
    Scanner scanner = new Scanner(inputStream, "UTF-8");
    List<String> dependencyLabels = new ArrayList<String>();
    while (scanner.hasNextLine()) {
        String dependencyLabel = scanner.nextLine();
        if (!dependencyLabel.startsWith("#"))
            dependencyLabels.add(dependencyLabel);
    }//ww w .ja  v  a  2  s . co m
    transitionSystem.setDependencyLabels(dependencyLabels);
    return transitionSystem;
}

From source file:org.apache.camel.processor.idempotent.FileIdempotentRepository.java

/**
 * Loads the given file store into the 1st level cache
 *//*  ww w. j a v  a 2 s.  c o m*/
protected void loadStore() {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Loading to 1st level cache from idempotent filestore: " + fileStore);
    }

    if (!fileStore.exists()) {
        return;
    }

    cache.clear();
    Scanner scanner = null;
    try {
        scanner = new Scanner(fileStore);
        scanner.useDelimiter(STORE_DELIMITER);
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            cache.put(line, line);
        }
    } catch (IOException e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Loaded " + cache.size() + " to the 1st level cache from idempotent filestore: " + fileStore);
    }
}

From source file:com.pinterest.clusterservice.cm.AwsVmManager.java

private Map<String, String> transformUserDataToConfigMap(String clusterName, String userData) throws Exception {
    String userDataString = userData.replace(String.format(AWS_USERDATA_TEMPLATE, clusterName, clusterName),
            "");/*from  w w  w. j  av a2  s .  c o  m*/
    Map<String, String> resultMap = new HashMap<>();
    if (userDataString.length() == 0) {
        return resultMap;
    }

    Scanner scanner = new Scanner(userDataString);
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        List<String> config = Arrays.asList(line.split(": "));
        if (config.size() == 2) {
            resultMap.put(config.get(0), config.get(1));
        }
    }
    scanner.close();
    return resultMap;
}

From source file:com.joliciel.talismane.machineLearning.TextFileWordList.java

public TextFileWordList(File file) {
    try {// www.java 2  s. c  o  m
        this.name = file.getName();

        Scanner scanner = new Scanner(
                new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")));
        int i = 1;
        String firstLine = scanner.nextLine();
        if (!firstLine.equals("Type: WordList")) {
            throw new JolicielException("A word list file must start with \"Type: WordList\"");
        }
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.length() > 0 && !line.startsWith("#")) {
                if (line.startsWith("Name: ")) {
                    this.name = line.substring("Name: ".length());
                    i++;
                    continue;
                }
                wordList.add(line);
            }
            i++;
        }
    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:org.apache.sling.testing.clients.SlingHttpResponse.java

/**
 * <p>For each regular expression, assert that at least one line of the response matches the expression</p>
 * <p>The regular expressions are automatically prefixed and suffixed with .* it order to partial-match the lines</p>
 *
 * @param regexp list of regular expressions
 * @throws AssertionError if the response content does not match one of the regexp
 *//*from www. j  av a2s .  c om*/
public void checkContentRegexp(String... regexp) throws ClientException {
    for (String expr : regexp) {
        final Pattern p = Pattern.compile(".*" + expr + ".*");
        final Scanner scanner = new Scanner(this.getContent());
        boolean matched = false;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (p.matcher(line).matches()) {
                matched = true;
                break;
            }
        }

        if (!matched) {
            throw new ClientException("Pattern " + p + " didn't match any line in content");
        }
    }
}

From source file:com.maxl.java.aips2xml.Aips2Xml.java

static void extractPackageInfo() {
    try {/*from   ww  w  . j  ava  2  s.  c o  m*/
        long startTime = System.currentTimeMillis();
        if (SHOW_LOGS)
            System.out.print("- Processing packages xls ... ");
        // Load Swissmedic xls file
        FileInputStream packages_file = new FileInputStream(FILE_PACKAGES_XLS);
        // Get workbook instance for XLS file (HSSF = Horrible SpreadSheet Format)
        HSSFWorkbook packages_workbook = new HSSFWorkbook(packages_file);
        // Get first sheet from workbook
        HSSFSheet packages_sheet = packages_workbook.getSheetAt(0);
        // Iterate through all rows of first sheet
        Iterator<Row> rowIterator = packages_sheet.iterator();

        int num_rows = 0;
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            if (num_rows > 3) {
                String swissmedic_no5 = ""; // SwissmedicNo5 registration number (5 digits)
                String sequence_name = "";
                String package_id = "";
                String swissmedic_no8 = ""; // SwissmedicNo8 = SwissmedicNo5 + Package id (8 digits)
                String heilmittel_code = "";
                String package_size = "";
                String package_unit = "";
                String swissmedic_cat = "";
                String application_area = "";
                String public_price = "";
                String exfactory_price = "";
                String therapeutic_index = "";
                String withdrawn_str = "";
                String speciality_str = "";
                String plimitation_str = "";
                String add_info_str = ""; // Contains additional information separated by ;

                // 0: Zulassungsnnr, 1: Sequenz, 2: Sequenzname, 3: Zulassunginhaberin, 4: T-Nummer, 5: ATC-Code, 6: Heilmittelcode
                // 7: Erstzulassung Prparat, 8: Zulassungsdatum Sequenz, 9: Gltigkeitsdatum, 10: Verpackung, 11: Packungsgrsse
                // 12: Einheit, 13: Abgabekategorie, 14: Wirkstoff, 15: Zusammensetzung, 16: Anwendungsgebiet Prparat, 17: Anwendungsgebiet Sequenz

                swissmedic_no5 = getAnyValue(row.getCell(0)); // Swissmedic registration number (5 digits)
                sequence_name = getAnyValue(row.getCell(2)); // Sequence name
                heilmittel_code = getAnyValue(row.getCell(6));
                package_size = getAnyValue(row.getCell(11));
                package_unit = getAnyValue(row.getCell(12));
                swissmedic_cat = getAnyValue(row.getCell(13));
                application_area = getAnyValue(row.getCell(16));

                if (row.getCell(10) != null) {
                    package_id = getAnyValue(row.getCell(10));
                    swissmedic_no8 = swissmedic_no5 + package_id;
                    // Fill in row
                    ArrayList<String> pack = new ArrayList<String>();
                    pack.add(swissmedic_no5); // 0
                    pack.add(sequence_name); // 1
                    pack.add(heilmittel_code); // 2
                    pack.add(package_size); // 3
                    pack.add(package_unit); // 4
                    pack.add(swissmedic_cat); // 5
                    if (!application_area.isEmpty())
                        pack.add(application_area + " (Swissmedic)\n"); // 6 = swissmedic + bag
                    else
                        pack.add("");
                    pack.add(public_price); // 7
                    pack.add(exfactory_price); // 8
                    pack.add(therapeutic_index); // 9
                    pack.add(withdrawn_str); // 10
                    pack.add(speciality_str); // 11   
                    pack.add(plimitation_str); // 12
                    pack.add(add_info_str); // 13

                    package_info.put(swissmedic_no8, pack);
                }
            }
            num_rows++;
        }
        long stopTime = System.currentTimeMillis();
        if (SHOW_LOGS) {
            System.out.println(
                    (package_info.size() + 1) + " packages in " + (stopTime - startTime) / 1000.0f + " sec");
        }
        startTime = System.currentTimeMillis();
        if (SHOW_LOGS)
            System.out.print("- Processing atc classes xls ... ");
        if (DB_LANGUAGE.equals("de")) {
            // Load ATC classes xls file
            FileInputStream atc_classes_file = new FileInputStream(FILE_ATC_CLASSES_XLS);
            // Get workbook instance for XLS file (HSSF = Horrible SpreadSheet Format)
            HSSFWorkbook atc_classes_workbook = new HSSFWorkbook(atc_classes_file);
            // Get first sheet from workbook
            HSSFSheet atc_classes_sheet = atc_classes_workbook.getSheetAt(1);
            // Iterate through all rows of first sheet
            rowIterator = atc_classes_sheet.iterator();

            num_rows = 0;
            while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                if (num_rows > 2) {
                    String atc_code = "";
                    String atc_class = "";
                    if (row.getCell(0) != null) {
                        atc_code = row.getCell(0).getStringCellValue().replaceAll("\\s", "");
                    }
                    if (row.getCell(2) != null) {
                        atc_class = row.getCell(2).getStringCellValue();
                    }
                    // Build a full map atc code to atc class
                    if (atc_code.length() > 0) {
                        atc_map.put(atc_code, atc_class);
                    }
                }
                num_rows++;
            }
        } else if (DB_LANGUAGE.equals("fr")) {
            // Load multilinguagl ATC classes txt file
            String atc_classes_multi = readFromFile(FILE_ATC_MULTI_LINGUAL_TXT);
            // Loop through all lines
            Scanner scanner = new Scanner(atc_classes_multi);
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                List<String> atc_class = Arrays.asList(line.split(": "));
                String atc_code = atc_class.get(0);
                String[] atc_classes_str = atc_class.get(1).split(";");
                String atc_class_french = atc_classes_str[1].trim();
                atc_map.put(atc_code, atc_class_french);
            }
            scanner.close();
        }
        stopTime = System.currentTimeMillis();
        if (SHOW_LOGS)
            System.out
                    .println((atc_map.size() + 1) + " classes in " + (stopTime - startTime) / 1000.0f + " sec");
        // Load Refdata xml file
        File refdata_xml_file = null;
        if (DB_LANGUAGE.equals("de"))
            refdata_xml_file = new File(FILE_REFDATA_PHARMA_DE_XML);
        else if (DB_LANGUAGE.equals("fr"))
            refdata_xml_file = new File(FILE_REFDATA_PHARMA_FR_XML);
        else {
            System.err.println("ERROR: DB_LANGUAGE undefined");
            System.exit(1);
        }
        FileInputStream refdata_fis = new FileInputStream(refdata_xml_file);

        startTime = System.currentTimeMillis();
        if (SHOW_LOGS)
            System.out.print("- Unmarshalling Refdata Pharma " + DB_LANGUAGE + " ... ");

        JAXBContext context = JAXBContext.newInstance(Pharma.class);
        Unmarshaller um = context.createUnmarshaller();
        Pharma refdataPharma = (Pharma) um.unmarshal(refdata_fis);
        List<Pharma.ITEM> pharma_list = refdataPharma.getItem();

        String smno8;
        for (Pharma.ITEM pharma : pharma_list) {
            String ean_code = pharma.getGtin();
            if (ean_code.length() == 13) {
                smno8 = ean_code.substring(4, 12);
                // Extract pharma corresponding to swissmedicno8
                ArrayList<String> pi_row = package_info.get(smno8);
                // Replace sequence_name
                if (pi_row != null) {
                    if (pharma.getAddscr().length() > 0)
                        pi_row.set(1, pharma.getDscr() + ", " + pharma.getAddscr());
                    else
                        pi_row.set(1, pharma.getDscr());
                    if (pharma.getStatus().equals("I")) {
                        if (DB_LANGUAGE.equals("de"))
                            pi_row.set(10, "a.H.");
                        else if (DB_LANGUAGE.equals("fr"))
                            pi_row.set(10, "p.c.");
                    }
                } else {
                    if (SHOW_ERRORS)
                        System.err.println(">> Does not exist in BAG xls: " + smno8 + " (" + pharma.getDscr()
                                + ", " + pharma.getAddscr() + ")");
                }

            } else if (ean_code.length() < 13) {
                if (SHOW_ERRORS)
                    System.err.println(">> EAN code too short: " + ean_code + ": " + pharma.getDscr());
            } else if (ean_code.length() > 13) {
                if (SHOW_ERRORS)
                    System.err.println(">> EAN code too long: " + ean_code + ": " + pharma.getDscr());
            }
        }

        stopTime = System.currentTimeMillis();
        if (SHOW_LOGS)
            System.out.println(pharma_list.size() + " medis in " + (stopTime - startTime) / 1000.0f + " sec");

        // Load BAG xml file               
        File bag_xml_file = new File(FILE_PREPARATIONS_XML);
        FileInputStream fis_bag = new FileInputStream(bag_xml_file);

        startTime = System.currentTimeMillis();
        if (SHOW_LOGS)
            System.out.print("- Processing preparations xml ... ");

        context = JAXBContext.newInstance(Preparations.class);
        um = context.createUnmarshaller();
        Preparations prepInfos = (Preparations) um.unmarshal(fis_bag);
        List<Preparations.Preparation> prep_list = prepInfos.getPreparations();

        int num_preparations = 0;
        for (Preparations.Preparation prep : prep_list) {
            String swissmedicno5_str = prep.getSwissmedicNo5();
            if (swissmedicno5_str != null) {
                String orggencode_str = ""; // "O", "G" or empty -> ""
                String flagSB20_str = ""; // "Y" -> 20% or "N" -> 10%                     
                if (prep.getOrgGenCode() != null)
                    orggencode_str = prep.getOrgGenCode();
                if (prep.getFlagSB20() != null) {
                    flagSB20_str = prep.getFlagSB20();
                    if (flagSB20_str.equals("Y")) {
                        if (DB_LANGUAGE.equals("de"))
                            flagSB20_str = "SB 20%";
                        else if (DB_LANGUAGE.equals("fr"))
                            flagSB20_str = "QP 20%";
                    } else if (flagSB20_str.equals("N")) {
                        if (DB_LANGUAGE.equals("de"))
                            flagSB20_str = "SB 10%";
                        else if (DB_LANGUAGE.equals("fr"))
                            flagSB20_str = "QP 10%";
                    } else
                        flagSB20_str = "";
                }
                add_info_map.put(swissmedicno5_str, orggencode_str + ";" + flagSB20_str);
            }

            List<Preparation.Packs> packs_list = prep.getPacks();
            for (Preparation.Packs packs : packs_list) {
                // Extract codes for therapeutic index / classification
                String bag_application = "";
                String therapeutic_code = "";
                List<Preparations.Preparation.ItCodes> itcode_list = prep.getItCodes();
                for (Preparations.Preparation.ItCodes itc : itcode_list) {
                    List<Preparations.Preparation.ItCodes.ItCode> code_list = itc.getItCode();
                    int index = 0;
                    for (Preparations.Preparation.ItCodes.ItCode code : code_list) {
                        if (index == 0) {
                            if (DB_LANGUAGE.equals("de"))
                                therapeutic_code = code.getDescriptionDe();
                            else if (DB_LANGUAGE.equals("fr"))
                                therapeutic_code = code.getDescriptionFr();
                        } else {
                            if (DB_LANGUAGE.equals("de"))
                                bag_application = code.getDescriptionDe();
                            else if (DB_LANGUAGE.equals("fr"))
                                bag_application = code.getDescriptionFr();
                        }
                        index++;
                    }
                }
                // Generate new package info
                List<Preparation.Packs.Pack> pack_list = packs.getPack();
                for (Preparation.Packs.Pack pack : pack_list) {
                    // Get SwissmedicNo8 and used it as a key to extract all the relevant package info
                    String swissMedicNo8 = pack.getSwissmedicNo8();
                    ArrayList<String> pi_row = package_info.get(swissMedicNo8);
                    // Preparation also in BAG xml file (we have a price)
                    if (pi_row != null) {
                        // Update Swissmedic catory if necessary ("N->A", Y->"A+")
                        if (pack.getFlagNarcosis().equals("Y"))
                            pi_row.set(5, pi_row.get(5) + "+");
                        // Extract point limitations
                        List<Preparations.Preparation.Packs.Pack.PointLimitations> point_limits = pack
                                .getPointLimitations();
                        for (Preparations.Preparation.Packs.Pack.PointLimitations limits : point_limits) {
                            List<Preparations.Preparation.Packs.Pack.PointLimitations.PointLimitation> plimits_list = limits
                                    .getPointLimitation();
                            if (plimits_list.size() > 0)
                                if (plimits_list.get(0) != null)
                                    pi_row.set(12, ", LIM" + plimits_list.get(0).getPoints() + "");
                        }
                        // Extract exfactory and public prices
                        List<Preparations.Preparation.Packs.Pack.Prices> price_list = pack.getPrices();
                        for (Preparations.Preparation.Packs.Pack.Prices price : price_list) {
                            List<Preparations.Preparation.Packs.Pack.Prices.PublicPrice> public_price = price
                                    .getPublicPrice();
                            List<Preparations.Preparation.Packs.Pack.Prices.ExFactoryPrice> exfactory_price = price
                                    .getExFactoryPrice();
                            if (exfactory_price.size() > 0) {
                                try {
                                    float f = Float.valueOf(exfactory_price.get(0).getPrice());
                                    String ep = String.format("%.2f", f);
                                    pi_row.set(8, "CHF " + ep);
                                } catch (NumberFormatException e) {
                                    if (SHOW_ERRORS)
                                        System.err.println("Number format exception (exfactory price): "
                                                + swissMedicNo8 + " (" + public_price.size() + ")");
                                }

                            }
                            if (public_price.size() > 0) {
                                try {
                                    float f = Float.valueOf(public_price.get(0).getPrice());
                                    String pp = String.format("%.2f", f);
                                    pi_row.set(7, "CHF " + pp);
                                    if (DB_LANGUAGE.equals("de"))
                                        pi_row.set(11, ", SL");
                                    else if (DB_LANGUAGE.equals("fr"))
                                        pi_row.set(11, ", LS");
                                } catch (NumberFormatException e) {
                                    if (SHOW_ERRORS)
                                        System.err.println("Number format exception (public price): "
                                                + swissMedicNo8 + " (" + public_price.size() + ")");
                                }
                            }
                            // Add application area and therapeutic code
                            if (!bag_application.isEmpty())
                                pi_row.set(6, pi_row.get(6) + bag_application + " (BAG)");
                            pi_row.set(9, therapeutic_code);
                        }
                    }
                }
            }
            num_preparations++;
        }

        stopTime = System.currentTimeMillis();
        if (SHOW_LOGS)
            System.out.println(
                    num_preparations + " preparations in " + (stopTime - startTime) / 1000.0f + " sec");

        // Loop through all SwissmedicNo8 numbers
        for (Map.Entry<String, ArrayList<String>> entry : package_info.entrySet()) {
            String swissmedicno8 = entry.getKey();
            ArrayList<String> pi_row = entry.getValue();
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}