读取训练文件中的标注集

@param filename
@return
330710
private boolean openTagSet(String filename)
    {
        int max_size = 0;
        InputStreamReader isr = null;
        y_.clear();
        try
        {
            isr = new InputStreamReader(IOUtil.newInputStream(filename), "UTF-8");
            BufferedReader br = new BufferedReader(isr);
            String line;
            while ((line = br.readLine()) != null)
            {
                if (line.length() == 0)
                {
                    continue;
                }
                char firstChar = line.charAt(0);
                if (firstChar == '\0' || firstChar == ' ' || firstChar == '\t')
                {
                    continue;
                }
                String[] cols = line.split("[\t ]", -1);
                if (max_size == 0)
                {
                    max_size = cols.length;
                }
                if (max_size != cols.length)
                {
                    String msg = "inconsistent column size: " + max_size +
                        " " + cols.length + " " + filename;
                    throw new RuntimeException(msg);
                }
                xsize_ = cols.length - 1;
                if (y_.indexOf(cols[max_size - 1]) == -1)
                {
                    y_.add(cols[max_size - 1]);
                }
            }
            Collections.sort(y_);
            br.close();
        }
        catch (Exception e)
        {
            if (isr != null)
            {
                try
                {
                    isr.close();
                }
                catch (Exception e2)
                {
                }
            }
            e.printStackTrace();
            System.err.println("Error reading " + filename);
            return false;
        }
        return true;
    }
1104516
public static String readTextFile(String fileName) {		
		try {
			return readText(new FileInputStream(new File(fileName)));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			
			return null;
		}
	}
1240494
public static String readFileContent(String filename) throws FileNotFoundException, IOException {
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        StringBuilder content = new StringBuilder();
        String line;
        final String eol = System.getProperty("line.separator");
        while ((line = reader.readLine()) != null) {
            content.append(line);
            content.append(eol);
        }
        reader.close();
        return content.toString();
    }
61966
public static String getURL(final String fileName) {

        if (fileName.startsWith("file:/")) {
            return fileName;
        } else {
            final File file = new File(fileName);
            return file.toURI().toString();
        }

    }
290432
public static String getSafeFilename(String filename)
   {
      String result = filename;
      if (result != null)
      {
         result = result.replaceAll("[^a-zA-Z0-9]+", "-").replaceAll("^-+", "");
      }
      return result;
   }
119921
public static String[] splitFileName(String fileName) {
	int pos = fileName.lastIndexOf('.');
	if (pos == -1) {
	    return new String[] { fileName };
	}
	return new String[] { fileName.substring(0, pos), fileName.substring(pos + 1) };
    }
1104023
@SuppressWarnings("unchecked")
    public static <T> T load(String fileName) {
        return (T) load(new File(fileName));
    }
23812
public static String getExtension(String fileName) {
        if (fileName == null)
            return null;

        String[] tokens = split(fileName);
        if (tokens.length >= 2)
            return tokens[tokens.length - 1];

        return null;
    }
645389
private static final String getExtension(String fileName) {
		return fileName.indexOf('.') == -1 ? null : fileName.substring(fileName.lastIndexOf('.') + 1);
	}
259205
public static byte[] readFile (String fileName) throws OSHelperException {
		File file = new File (fileName);
		if (!file.exists ()) {
			throw new OSHelperException ("File " + fileName + " does not exist");
		}
		if (!file.canRead ()) {
			throw new OSHelperException ("File " + fileName + " is not readable");
		}
		if (!file.isFile ()) {
			throw new OSHelperException ("File " + fileName + " is not a normal file");
		}

		RandomAccessFile raFile = null;
		try {
			raFile = new RandomAccessFile (fileName, "r");
		} catch (FileNotFoundException ex) {
			throw new OSHelperException ("File " + fileName + " not found");
		}

		long fileLengthLong;
		try {
			fileLengthLong = raFile.length ();
		} catch (IOException ex) {
			throw new OSHelperException (ex);
		}
		if (fileLengthLong > Integer.MAX_VALUE) {
			throw new OSHelperException ("File length exceeds " + Integer.MAX_VALUE + " bytes: " + fileLengthLong);
		}

		int fileLengthInt = (int) fileLengthLong;

		byte[] bytes = new byte[fileLengthInt];
		try {
			raFile.read (bytes);
		} catch (IOException ex) {
			throw new OSHelperException (ex);
		} finally {
			try {
				raFile.close ();
			} catch (IOException ex) {
				throw new OSHelperException (ex);
			}
		}

		return bytes;
	}
1080260
private static int getIndexFromFilename(String fileName) {
        // remove the beginning of the file name
        String resStr = fileName.replace(
                latestMOTDSerializedFileName.substring(0, latestMOTDSerializedFileName.indexOf("{index}")), "");

        // remove the end of the file name
        resStr = resStr.replace(
                latestMOTDSerializedFileName.substring(latestMOTDSerializedFileName.indexOf("{index}") + 7), "");

        return Integer.parseInt(resStr);
    }
1330745
@Pure
	public static String[] split(File filename) {
		if (filename == null) {
			return new String[0];
		}
		return filename.getPath().split(Pattern.quote(File.separator));
	}
558751
private static String getFileExtension(final String filename) {

		String extension = "";
		int i = filename.lastIndexOf('.');
		int p = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
		if (i > p)
			extension = filename.substring(i+1);

		return extension;
	}
521082
private static String readFile(String filename)
                    throws	FileNotFoundException,
                            SecurityException,
                            IOException
    {
        FileInputStream	fid = new FileInputStream(filename);
        int nb = fid.available();
        byte[]	inStr  = new byte[nb];
        nb = fid.read(inStr);
        fid.close();
        return new String(inStr);
    }
901610
public static File fileFromString(String fileName) {
        try {
            return new File(new URI(fileName).getPath());
        } catch (URISyntaxException ex ) {
            // Not a valid uri
            return new File(fileName);
        }
    }
80307
public String read(final String filename) {
        if (isFresh(filename)) {
            String cachedValue = getFileFromCache(filename);
            if (cachedValue != null) {
                return cachedValue;
            }
        }
        // either fresh is false or cachedValue is null
        loadToCache(filename);
        return getFileFromCache(filename);
    }
173235
public static String getExtension(String fileName) {
        if (fileName == null)
            return null;
        if (fileName.isEmpty())
            return "";

        int idx = fileName.lastIndexOf(".");
        if (idx != -1) {
            return fileName.substring(idx);
        } else {
            return "";
        }
    }