@Override public void close() throws IOException { mDelegate.close(); }
/** * Finds the start position in the property file. We assume that the key is the first match on a * line. * * @param propertyName the property name * @return the start position of the property name in the file, -1 if not found */ private int findPropertyNameStartPosition(String propertyName) { // Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=19319 InputStream stream = null; LineReader lineReader = null; String encoding; try { encoding = fPropertiesFile.getCharset(); } catch (CoreException e1) { encoding = "ISO-8859-1"; // $NON-NLS-1$ } try { stream = createInputStream(fPropertiesFile); lineReader = new LineReader(stream, encoding); } catch (CoreException cex) { // failed to get input stream JavaPlugin.log(cex); return -1; } catch (IOException e) { if (stream != null) { try { stream.close(); } catch (IOException ce) { JavaPlugin.log(ce); } } return -1; } int start = 0; try { StringBuffer buf = new StringBuffer(80); int eols = lineReader.readLine(buf); int keyLength = propertyName.length(); while (eols > 0) { String line = buf.toString(); int i = line.indexOf(propertyName); int charPos = i + keyLength; char terminatorChar = 0; boolean hasNoValue = (charPos >= line.length()); if (i > -1 && !hasNoValue) terminatorChar = line.charAt(charPos); if (line.trim().startsWith(propertyName) && (hasNoValue || Character.isWhitespace(terminatorChar) || terminatorChar == '=')) { start += line.indexOf(propertyName); eols = -17; // found key } else { start += line.length() + eols; buf.setLength(0); eols = lineReader.readLine(buf); } } if (eols != -17) start = -1; // key not found in file. See bug 63794. This can happen if the key contains escaped // characters. } catch (IOException ex) { JavaPlugin.log(ex); return -1; } finally { try { lineReader.close(); } catch (IOException ex) { JavaPlugin.log(ex); } } return start; }