fixed sonar findings
This commit is contained in:
@ -16,67 +16,67 @@ public class BOM {
|
||||
/**
|
||||
* UTF32(Big Endian)
|
||||
*/
|
||||
public static final int[] BOM_UTF32_BE = {0x00, 0x00, 0xFE, 0xFF}; //
|
||||
protected static final int[] BOM_UTF32_BE = {0x00, 0x00, 0xFE, 0xFF}; //
|
||||
/**
|
||||
* UTF32(Little Endian)
|
||||
*/
|
||||
public static final int[] BOM_UTF32_LE = {0xFF, 0xFE, 0x00, 0x00}; //
|
||||
protected static final int[] BOM_UTF32_LE = {0xFF, 0xFE, 0x00, 0x00}; //
|
||||
/**
|
||||
* UTF-1
|
||||
*/
|
||||
public static final int[] BOM_UTF1 = {0xF7, 0x64, 0x4C}; // UTF-1
|
||||
protected static final int[] BOM_UTF1 = {0xF7, 0x64, 0x4C}; // UTF-1
|
||||
/**
|
||||
* UTF7 - version 1
|
||||
*/
|
||||
public static final int[] BOM_UTF7_1 = {0x2B, 0x2F, 0x76, 0x38}; // UTF-7
|
||||
protected static final int[] BOM_UTF7_1 = {0x2B, 0x2F, 0x76, 0x38}; // UTF-7
|
||||
/**
|
||||
* UTF7 - version 2
|
||||
*/
|
||||
public static final int[] BOM_UTF7_2 = {0x2B, 0x2F, 0x76, 0x39}; // UTF-7
|
||||
protected static final int[] BOM_UTF7_2 = {0x2B, 0x2F, 0x76, 0x39}; // UTF-7
|
||||
/**
|
||||
* UTF7 - version 3
|
||||
*/
|
||||
public static final int[] BOM_UTF7_3 = {0x2B, 0x2F, 0x76, 0x2B}; // UTF-7
|
||||
protected static final int[] BOM_UTF7_3 = {0x2B, 0x2F, 0x76, 0x2B}; // UTF-7
|
||||
/**
|
||||
* UTF7 - version 4
|
||||
*/
|
||||
public static final int[] BOM_UTF7_4 = {0x2B, 0x2F, 0x76, 0x2F}; // UTF-7
|
||||
protected static final int[] BOM_UTF7_4 = {0x2B, 0x2F, 0x76, 0x2F}; // UTF-7
|
||||
/**
|
||||
* UTF-EBCDIC
|
||||
*/
|
||||
public static final int[] BOM_UTF_EBCDIC = {0xDD, 0x73, 0x66, 0x73}; // UTF - EBCDIC
|
||||
protected static final int[] BOM_UTF_EBCDIC = {0xDD, 0x73, 0x66, 0x73}; // UTF - EBCDIC
|
||||
/**
|
||||
* UTF-8
|
||||
*/
|
||||
public static final int[] BOM_UTF8 = {0xEF, 0xBB, 0xBF}; // UTF-8
|
||||
protected static final int[] BOM_UTF8 = {0xEF, 0xBB, 0xBF}; // UTF-8
|
||||
/**
|
||||
* SCSU
|
||||
*/
|
||||
public static final int[] BOM_SCSU = {0x0E, 0xFE, 0xFF}; // SCSU
|
||||
protected static final int[] BOM_SCSU = {0x0E, 0xFE, 0xFF}; // SCSU
|
||||
/**
|
||||
* BOCU-1 - version 1
|
||||
*/
|
||||
public static final int[] BOM_BOCU1_1 = {0xFB, 0xEE, 0x28}; // BOCU-1
|
||||
protected static final int[] BOM_BOCU1_1 = {0xFB, 0xEE, 0x28}; // BOCU-1
|
||||
/**
|
||||
* BOCU-2 - version 2
|
||||
*/
|
||||
public static final int[] BOM_BOCU1_2 = {0xFB, 0xEE, 0x28, 0xFF}; // BOCU-1
|
||||
protected static final int[] BOM_BOCU1_2 = {0xFB, 0xEE, 0x28, 0xFF}; // BOCU-1
|
||||
/**
|
||||
* UTF-16 - big endian
|
||||
*/
|
||||
public static final int[] BOM_UTF16_BE = {0xFE, 0xFF}; // UTF-16 (Big Endian)
|
||||
protected static final int[] BOM_UTF16_BE = {0xFE, 0xFF}; // UTF-16 (Big Endian)
|
||||
/**
|
||||
* UTF-16 - little endian
|
||||
*/
|
||||
public static final int[] BOM_UTF16_LE = {0xFF, 0xFE}; // UTF-16 (Little Endian)
|
||||
protected static final int[] BOM_UTF16_LE = {0xFF, 0xFE}; // UTF-16 (Little Endian)
|
||||
/**
|
||||
* GB-18030
|
||||
*/
|
||||
public static final int[] BOM_GB_18030 = {0x84, 0x31, 0x95, 0x33}; // GB-18030
|
||||
protected static final int[] BOM_GB_18030 = {0x84, 0x31, 0x95, 0x33}; // GB-18030
|
||||
/**
|
||||
* mapping from bom bytes to encoding name
|
||||
*/
|
||||
private static Map<BOM, String> bomMap = null;
|
||||
private static volatile Map<BOM, String> bomMap = null;
|
||||
/**
|
||||
* key1 of the BOM
|
||||
*/
|
||||
@ -94,28 +94,6 @@ public class BOM {
|
||||
*/
|
||||
private int key4 = 0;
|
||||
|
||||
/**
|
||||
* setups the bom bytes to encoding name map
|
||||
*/
|
||||
private static void initBomMap() {
|
||||
bomMap = new HashMap<>();
|
||||
bomMap.put(new BOM(BOM_UTF1), "UTF-1");
|
||||
bomMap.put(new BOM(BOM_UTF7_1), "UTF-7");
|
||||
bomMap.put(new BOM(BOM_UTF7_2), "UTF-7");
|
||||
bomMap.put(new BOM(BOM_UTF7_3), "UTF-7");
|
||||
bomMap.put(new BOM(BOM_UTF7_4), "UTF-7");
|
||||
bomMap.put(new BOM(BOM_UTF8), "UTF-8");
|
||||
bomMap.put(new BOM(BOM_UTF16_BE), "UTF-16_BE");
|
||||
bomMap.put(new BOM(BOM_UTF16_LE), "UTF-16_LE");
|
||||
bomMap.put(new BOM(BOM_UTF32_BE), "UTF-32_BE");
|
||||
bomMap.put(new BOM(BOM_UTF32_LE), "UTF-32_LE");
|
||||
bomMap.put(new BOM(BOM_UTF_EBCDIC), "UTF_EBCDIC");
|
||||
bomMap.put(new BOM(BOM_SCSU), "UTF-8");
|
||||
bomMap.put(new BOM(BOM_BOCU1_1), "BOCU-1");
|
||||
bomMap.put(new BOM(BOM_BOCU1_2), "BOCU-1");
|
||||
bomMap.put(new BOM(BOM_GB_18030), "GB-18030");
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new instance of a BOM
|
||||
*
|
||||
@ -182,13 +160,14 @@ public class BOM {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true, if the given object is a BOM and represents the same encoding as this object
|
||||
* returns true, if the given object is a BOM and represents the same
|
||||
* encoding as this object
|
||||
*
|
||||
* @param o the object to compare to
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof BOM) {
|
||||
if (o.getClass() == this.getClass()) {
|
||||
BOM b = (BOM) o;
|
||||
boolean equalsKey1 = this.key1 == b.key1;
|
||||
boolean equalsKey2 = this.key2 == b.key2;
|
||||
@ -220,11 +199,28 @@ public class BOM {
|
||||
*
|
||||
* @param bomBytes the bytes representing the bom
|
||||
* @return the name of the encoding for the given bom bytes
|
||||
* @throws UnsupportedEncodingException if no valid encoding name can be found
|
||||
* @throws UnsupportedEncodingException if no valid encoding name can be
|
||||
* found
|
||||
*/
|
||||
public static String getEncoding(final int[] bomBytes) throws UnsupportedEncodingException {
|
||||
if (bomMap == null) {
|
||||
initBomMap();
|
||||
|
||||
bomMap = new HashMap<>();
|
||||
bomMap.put(new BOM(BOM_UTF1), "UTF-1");
|
||||
bomMap.put(new BOM(BOM_UTF7_1), "UTF-7");
|
||||
bomMap.put(new BOM(BOM_UTF7_2), "UTF-7");
|
||||
bomMap.put(new BOM(BOM_UTF7_3), "UTF-7");
|
||||
bomMap.put(new BOM(BOM_UTF7_4), "UTF-7");
|
||||
bomMap.put(new BOM(BOM_UTF8), "UTF-8");
|
||||
bomMap.put(new BOM(BOM_UTF16_BE), "UTF-16_BE");
|
||||
bomMap.put(new BOM(BOM_UTF16_LE), "UTF-16_LE");
|
||||
bomMap.put(new BOM(BOM_UTF32_BE), "UTF-32_BE");
|
||||
bomMap.put(new BOM(BOM_UTF32_LE), "UTF-32_LE");
|
||||
bomMap.put(new BOM(BOM_UTF_EBCDIC), "UTF_EBCDIC");
|
||||
bomMap.put(new BOM(BOM_SCSU), "UTF-8");
|
||||
bomMap.put(new BOM(BOM_BOCU1_1), "BOCU-1");
|
||||
bomMap.put(new BOM(BOM_BOCU1_2), "BOCU-1");
|
||||
bomMap.put(new BOM(BOM_GB_18030), "GB-18030");
|
||||
}
|
||||
|
||||
BOM currentBOM = new BOM(bomBytes);
|
||||
@ -234,4 +230,4 @@ public class BOM {
|
||||
throw new UnsupportedEncodingException("Not supported encoding found");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ public class BOMStripperInputStream extends PushbackInputStream {
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/Byte-order_mark for details
|
||||
*/
|
||||
public static final int[][] BOMS = {
|
||||
protected static final int[][] BOMS = {
|
||||
BOM.BOM_UTF32_BE,
|
||||
BOM.BOM_UTF32_LE,
|
||||
BOM.BOM_UTF1,
|
||||
|
||||
@ -19,6 +19,7 @@ import java.text.Format;
|
||||
import static java.util.Arrays.asList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -66,12 +67,15 @@ public abstract class FileUtil {
|
||||
} // method getFilesFromDirecotry
|
||||
|
||||
/**
|
||||
* returns a file handle to a file in the given folder using the given formater and the given number.
|
||||
* returns a file handle to a file in the given folder using the given
|
||||
* formater and the given number.
|
||||
*
|
||||
* @param outputFolder the folder to link the file to as strnig
|
||||
* @param ft a format object to use to format the filename of the given file
|
||||
* @param number a number used to call the given formater to name the file number
|
||||
* @return a file handle build from formater and number linked to given directory
|
||||
* @param number a number used to call the given formater to name the file
|
||||
* number
|
||||
* @return a file handle build from formater and number linked to given
|
||||
* directory
|
||||
*/
|
||||
public static File getFileName(final String outputFolder, final Format ft, final int number) {
|
||||
String folderName = outputFolder;
|
||||
@ -198,7 +202,10 @@ public abstract class FileUtil {
|
||||
}
|
||||
message = s.toString();
|
||||
} catch (FileNotFoundException fnex) {
|
||||
throw new FileNotFoundException("Error occured while reading file. Reason:" + fnex.getMessage());
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.log(Level.DEBUG, "Error occured while readoing file. Reason:" + fnex, fnex);
|
||||
}
|
||||
throw new FileNotFoundException("Error occured while reading file. Reason:" + fnex);
|
||||
}
|
||||
|
||||
return message;
|
||||
|
||||
@ -8,7 +8,7 @@ import java.io.InputStream;
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
*/
|
||||
public class DefaultTest {
|
||||
public abstract class DefaultTest {
|
||||
|
||||
public String readContentFromFile(String name) throws IOException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user