Changeset 13061 in josm for trunk/src/com/drew/metadata/iptc/Iso2022Converter.java
- Timestamp:
- 2017-10-30T22:46:09+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/iptc/Iso2022Converter.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 59 59 60 60 /** 61 * Attempts to guess the encodingof a string provided as a byte array.61 * Attempts to guess the {@link Charset} of a string provided as a byte array. 62 62 * <p> 63 * Encodings trialled are, in order:63 * Charsets trialled are, in order: 64 64 * <ul> 65 65 * <li>UTF-8</li> … … 68 68 * </ul> 69 69 * <p> 70 * Its only purpose is to guess the encodingif and only ifiptctag coded character set is not set. If the70 * Its only purpose is to guess the Charset if and only if IPTC tag coded character set is not set. If the 71 71 * encoding is not UTF-8, the tag should be set. Otherwise it is bad practice. This method tries to 72 72 * workaround this issue since some metadata manipulating tools do not prevent such bad practice. … … 79 79 */ 80 80 @Nullable 81 static String guessEncoding(@NotNull final byte[] bytes)81 static Charset guessCharSet(@NotNull final byte[] bytes) 82 82 { 83 83 String[] encodings = { UTF_8, System.getProperty("file.encoding"), ISO_8859_1 }; … … 85 85 for (String encoding : encodings) 86 86 { 87 CharsetDecoder cs = Charset.forName(encoding).newDecoder(); 87 Charset charset = Charset.forName(encoding); 88 CharsetDecoder cs = charset.newDecoder(); 88 89 89 90 try { 90 91 cs.decode(ByteBuffer.wrap(bytes)); 91 return encoding;92 return charset; 92 93 } catch (CharacterCodingException e) { 93 94 // fall through...
Note:
See TracChangeset
for help on using the changeset viewer.
