/** * Adds a blank line to the end of a section. * * @param section the section's name * @throws IniEditor.NoSuchSectionException no section with the given name exists */ public void addBlankLine(String section) { if (hasSection(section)) { getSection(section).addBlankLine(); } else { throw new NoSuchSectionException(section); } }
/** * Checks whether an option exists in a given section. Options in the * common section are assumed to not exist in particular sections, * unless they're overwritten. * * @param section the section's name * @param option the option's name * @return true if the given section has the option */ public boolean hasOption(String section, String option) { return hasSection(section) && getSection(section).hasOption(option); }
/** * After all the data has been added to the message digest via add methods, * this method is used to finalize the digest calcualation and return the digest as a String. You can get the * actual bytes of the digest if you call {@link #getDigest()} instead. * * @return the digest as a string */ public String getDigestString() { return calculateDigestStringFromBytes(getDigest()); }
/** * Calculates a digest for a given string and returns the digest's String representation. * * @param source_str the string whose contents will be used as the data to calculate the digest * * @return the string's digest or hash as a String */ public static String getDigestString(String source_str) { MessageDigestGenerator md5 = new MessageDigestGenerator(MD5); return md5.calcDigestString(source_str); }
/** * Calculates the digest for a given file. The file's contents will be used as the source data for the digest calculation. * * @param file the file whose contents are to be used to calculate the digest. * * @return the file content's digest * * @throws IOException if the file could not be read or accessed */ public static byte[] getDigest(File file) throws IOException { MessageDigestGenerator md5 = new MessageDigestGenerator(MD5); return md5.calcDigest(file); }
/** * Returns all option names of a section, not including options from the * common section. * * @param section the section's name * @return list of option names * @throws IniEditor.NoSuchSectionException no section with the given name exists */ public List<String> optionNames(String section) { if (hasSection(section)) { return getSection(section).optionNames(); } else { throw new NoSuchSectionException(section); } }
/** * Returns an option's value. * * @param option the name of the option * @return the requested option's value or <code>null</code> if no * option with the specified name exists */ public String get(String option) { String normed = normOption(option); if (hasOption(normed)) { return getOption(normed).value(); } return null; }
/** * Removes an option from a section if it exists. Will not remove options * from the common section if it's not directly addressed. * * @param section the section's name * @param option the option's name * @return <code>true</code> if the option was actually removed * @throws IniEditor.NoSuchSectionException no section with the given name exists */ public boolean remove(String section, String option) { if (hasSection(section)) { return getSection(section).remove(option); } else { throw new NoSuchSectionException(section); } }
/** * Adds a comment line to the end of a section. A comment spanning * several lines (ie with line breaks) will be split up, one comment * line for each line. * * @param section the section's name * @param comment the comment * @throws IniEditor.NoSuchSectionException no section with the given name exists */ public void addComment(String section, String comment) { if (hasSection(section)) { getSection(section).addComment(comment); } else { throw new NoSuchSectionException(section); } }
/** * Returns base64 representation of specified byte array. */ public static String encode(byte[] data) { return encode(data, 0, data.length); }
/** * Print out an array as a String */ public static String arrayToString(Object[] array) { return arrayToString(array, ','); }
/** * Print out a List in a user-friendly string format. * * @param list A List to print out. * * @return The List in a user-friendly string format. */ public static String listToString(List<?> list) { return listToString(list, ","); }
/** * Sets an option's value and creates the option if it doesn't exist. * * @param option the option's name * @param value the option's value * @throws IllegalArgumentException the option name is illegal, * ie contains a '=' character or consists only of white space */ public void set(String option, String value) { set(option, value, this.optionDelims[0]); }
/** * Adds a comment line to the end of this section. A comment spanning * several lines (ie with line breaks) will be split up, one comment * line for each line. * * @param comment the comment */ public void addComment(String comment) { addComment(comment, this.commentDelims[0]); }
/** * Print out everything in an Iterator in a user-friendly string format. * * @param i An iterator to print out. * @param delim The delimiter to use between elements. * * @return The Iterator's elements in a user-friendly string format. */ public static String iteratorToString(Iterator<?> i, String delim) { return iteratorToString(i, delim, ""); }
/** * @param s A string that might contain unix-style path separators. * * @return The correct path for this platform (i.e, if win32, replace / with \). */ public static String normalizePath(String s) { return StringUtil.replace(s, "/", File.separator); }
/** * Similar to {@link #getDigest(InputStream)}, only this returns the digest as a String. * * @param is the stream whose data is to be used to calculate the digest * * @return the stream data's digest as a String * * @throws IOException if failed to read the stream for some reason */ public static String getDigestString(InputStream is) throws IOException { MessageDigestGenerator md5 = new MessageDigestGenerator(MD5); return md5.calcDigestString(is); }
/** * Calculates the digest for a given file. The file's contents will be used as the source data for the digest calculation. * * @param url the URL whose contents are to be used to calculate the digest. * * @return the URL content's digest as a String * * @throws IOException if the URL could not be read or accessed */ public static String getDigestString(URL url) throws IOException { MessageDigestGenerator md5 = new MessageDigestGenerator(MD5); return md5.calcDigestString(url); }
/** * Calculates the digest for a given file. The file's contents will be used as the source data for the digest calculation. * * @param file the file whose contents are to be used to calculate the digest. * * @return the file content's digest as a String * * @throws IOException if the file could not be read or accessed */ public static String getDigestString(File file) throws IOException { MessageDigestGenerator md5 = new MessageDigestGenerator(MD5); return md5.calcDigestString(file); }