Here you can find the source of loadTwoColumnResource(InputStream resource)
Parameter | Description |
---|---|
resource | : InputStream containing the two column resource |
Parameter | Description |
---|---|
IOException | if the given resource has reading problems. |
public static HashMap<String, String> loadTwoColumnResource(InputStream resource) throws IOException
//package com.java2s; /*/* ww w . ja v a 2 s . c om*/ * Copyright 2014 Elhuyar Fundazioa This file is part of EliXa. EliXa is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. EliXa is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with EliXa. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; public class Main { /** * Function reads two column file and stores the values into a HashMap<String,String> object * * @param resource : InputStream containing the two column resource * @return HashMap<String,String> contains the elements and their respective attribute values * * @throws IOException if the given resource has reading problems. */ public static HashMap<String, String> loadTwoColumnResource(InputStream resource) throws IOException { HashMap<String, String> result = new HashMap<String, String>(); BufferedReader breader = new BufferedReader(new InputStreamReader(resource)); String line; while ((line = breader.readLine()) != null) { if (line.startsWith("#") || line.matches("^\\s*$")) { continue; } String[] fields = line.split("\t"); try { result.put(fields[0], fields[1]); } catch (IndexOutOfBoundsException ioobe) { System.err.println("FileUtilsElh::loadTwoColumnResource - " + line); } } breader.close(); return result; } }