Lines 325-413
Link Here
|
325 |
*/ |
325 |
*/ |
326 |
private int findPropertyNameStartPosition(String propertyName) { |
326 |
private int findPropertyNameStartPosition(String propertyName) { |
327 |
// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=19319 |
327 |
// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=19319 |
328 |
InputStream stream= null; |
|
|
329 |
LineReader lineReader= null; |
330 |
String encoding; |
328 |
String encoding; |
331 |
try { |
329 |
try { |
332 |
encoding= fPropertiesFile.getCharset(); |
330 |
encoding= fPropertiesFile.getCharset(); |
333 |
} catch (CoreException e1) { |
331 |
} catch (CoreException e1) { |
334 |
encoding= "ISO-8859-1"; //$NON-NLS-1$ |
332 |
encoding= "ISO-8859-1"; //$NON-NLS-1$ |
335 |
} |
333 |
} |
336 |
try { |
334 |
try (InputStream stream= createInputStream(fPropertiesFile)) { |
337 |
stream= createInputStream(fPropertiesFile); |
335 |
try (LineReader lineReader= new LineReader(stream, encoding)) { |
338 |
lineReader= new LineReader(stream, encoding); |
336 |
int start= 0; |
|
|
337 |
try { |
338 |
StringBuffer buf= new StringBuffer(80); |
339 |
int eols= lineReader.readLine(buf); |
340 |
int keyLength= propertyName.length(); |
341 |
while (eols > 0) { |
342 |
String line= buf.toString(); |
343 |
int i= line.indexOf(propertyName); |
344 |
int charPos= i + keyLength; |
345 |
char terminatorChar= 0; |
346 |
boolean hasNoValue= (charPos >= line.length()); |
347 |
if (i > -1 && !hasNoValue) |
348 |
terminatorChar= line.charAt(charPos); |
349 |
if (line.trim().startsWith(propertyName) && |
350 |
(hasNoValue || Character.isWhitespace(terminatorChar) || terminatorChar == '=')) { |
351 |
start += line.indexOf(propertyName); |
352 |
eols= -17; // found key |
353 |
} else { |
354 |
start += line.length() + eols; |
355 |
buf.setLength(0); |
356 |
eols= lineReader.readLine(buf); |
357 |
} |
358 |
} |
359 |
if (eols != -17) |
360 |
start= -1; //key not found in file. See bug 63794. This can happen if the key contains escaped characters. |
361 |
} catch (IOException ex) { |
362 |
JavaPlugin.log(ex); |
363 |
return -1; |
364 |
} |
365 |
return start; |
366 |
} |
339 |
} catch (CoreException cex) { |
367 |
} catch (CoreException cex) { |
340 |
// failed to get input stream |
368 |
// failed to get input stream |
341 |
JavaPlugin.log(cex); |
369 |
JavaPlugin.log(cex); |
342 |
return -1; |
370 |
return -1; |
343 |
} catch (IOException e) { |
371 |
} catch (IOException e) { |
344 |
if (stream != null) { |
372 |
JavaPlugin.log(e); |
345 |
try { |
|
|
346 |
stream.close(); |
347 |
} catch (IOException ce) { |
348 |
JavaPlugin.log(ce); |
349 |
} |
350 |
} |
351 |
return -1; |
373 |
return -1; |
352 |
} |
374 |
} |
353 |
int start= 0; |
|
|
354 |
try { |
355 |
StringBuffer buf= new StringBuffer(80); |
356 |
int eols= lineReader.readLine(buf); |
357 |
int keyLength= propertyName.length(); |
358 |
while (eols > 0) { |
359 |
String line= buf.toString(); |
360 |
int i= line.indexOf(propertyName); |
361 |
int charPos= i + keyLength; |
362 |
char terminatorChar= 0; |
363 |
boolean hasNoValue= (charPos >= line.length()); |
364 |
if (i > -1 && !hasNoValue) |
365 |
terminatorChar= line.charAt(charPos); |
366 |
if (line.trim().startsWith(propertyName) && |
367 |
(hasNoValue || Character.isWhitespace(terminatorChar) || terminatorChar == '=')) { |
368 |
start += line.indexOf(propertyName); |
369 |
eols= -17; // found key |
370 |
} else { |
371 |
start += line.length() + eols; |
372 |
buf.setLength(0); |
373 |
eols= lineReader.readLine(buf); |
374 |
} |
375 |
} |
376 |
if (eols != -17) |
377 |
start= -1; //key not found in file. See bug 63794. This can happen if the key contains escaped characters. |
378 |
} catch (IOException ex) { |
379 |
JavaPlugin.log(ex); |
380 |
return -1; |
381 |
} finally { |
382 |
try { |
383 |
lineReader.close(); |
384 |
} catch (IOException ex) { |
385 |
JavaPlugin.log(ex); |
386 |
} |
387 |
} |
388 |
return start; |
389 |
} |
375 |
} |
390 |
|
376 |
|
391 |
private void loadProperties() { |
377 |
private void loadProperties() { |
392 |
Set<Object> duplicateKeys= new HashSet<>(); |
378 |
Set<Object> duplicateKeys= new HashSet<>(); |
393 |
fProperties= new Properties(duplicateKeys); |
379 |
fProperties= new Properties(duplicateKeys); |
394 |
InputStream stream; |
380 |
try (InputStream stream= new BufferedInputStream(createInputStream(fPropertiesFile))) { |
395 |
try { |
381 |
fProperties.load(stream); |
396 |
stream= new BufferedInputStream(createInputStream(fPropertiesFile)); |
|
|
397 |
} catch (CoreException ex) { |
382 |
} catch (CoreException ex) { |
398 |
fProperties= new Properties(); |
383 |
fProperties= new Properties(); |
399 |
return; |
384 |
return; |
400 |
} |
|
|
401 |
try { |
402 |
fProperties.load(stream); |
403 |
} catch (IOException ex) { |
385 |
} catch (IOException ex) { |
404 |
fProperties= new Properties(); |
386 |
fProperties= new Properties(); |
405 |
return; |
387 |
return; |
406 |
} finally { |
388 |
} finally { |
407 |
try { |
|
|
408 |
stream.close(); |
409 |
} catch (IOException ex) { |
410 |
} |
411 |
reportDuplicateKeys(duplicateKeys); |
389 |
reportDuplicateKeys(duplicateKeys); |
412 |
} |
390 |
} |
413 |
} |
391 |
} |