fixed sonar findings

This commit is contained in:
jomu
2015-11-01 18:30:42 +00:00
parent 268ca04a69
commit 8fa14d6309
32 changed files with 174 additions and 298 deletions

View File

@ -6,12 +6,7 @@ package de.muehlencord.shared.configuration;
*/
public class ConfigurationException extends Exception {
/**
* Creates a new instance of
* <code>ParameterException</code> without detail message.
*/
public ConfigurationException() {
}
private static final long serialVersionUID = 2714239259852576278L;
/**
* Constructs an instance of

View File

@ -6,12 +6,8 @@ package de.muehlencord.shared.configuration;
*/
public class ConverterException extends Exception {
/**
* Creates a new instance of
* <code>ConverterException</code> without detail message.
*/
public ConverterException() {
}
private static final long serialVersionUID = 3587621400600640847L;
/**
* Constructs an instance of

View File

@ -1,5 +1,6 @@
package de.muehlencord.shared.configuration;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
@ -121,7 +122,7 @@ public abstract class Parameter<T> {
* @return the list of parameters the given parameter requires
*/
public List<Parameter<?>> getRequiredParameter() {
return requiredParameters;
return new ArrayList<>(requiredParameters);
}
/**
@ -149,10 +150,9 @@ public abstract class Parameter<T> {
if (o == null) {
return false;
}
if (o instanceof Parameter) {
if (o.getClass() == this.getClass()) {
Parameter param = (Parameter) o;
return param.getName().equals(getName());
} else {
return false;
}

View File

@ -6,12 +6,8 @@ package de.muehlencord.shared.configuration;
*/
public class ValidationException extends Exception {
/**
* Creates a new instance of
* <code>ValidationException</code> without detail message.
*/
public ValidationException() {
}
private static final long serialVersionUID = -5137890709720975939L;
/**
* Constructs an instance of

View File

@ -1,38 +0,0 @@
package de.muehlencord.shared.configuration;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}

View File

@ -19,7 +19,7 @@ public class IpInformation {
/* *** getter / setter *** */
public List<PortInformation> getPortInformation() {
return portInformation;
return new ArrayList<>(portInformation);
}
public List<PortInformation> getOpenPorts() {
@ -34,7 +34,7 @@ public class IpInformation {
}
public void setPortInformation(List<PortInformation> portInformation) {
this.portInformation = portInformation;
this.portInformation = new ArrayList<>(portInformation);
}
public String getIpAddress() {

View File

@ -16,7 +16,7 @@ public class NetworkScanner {
private final static Logger LOGGER = LogManager.getLogger(NetworkScanner.class);
private String networkString;
private NetworkInformation networkInformation = null; // TODO add scan for information
// private NetworkInformation networkInformation = null; // TODO add scan for information
private List<IpInformation> ipinformationList = new ArrayList<>();
public NetworkScanner(String network) {
@ -43,7 +43,7 @@ public class NetworkScanner {
}
public List<IpInformation> getIpsInNetwork() {
return ipinformationList;
return new ArrayList<>(ipinformationList);
}
private boolean atLeastOnePortOpen(List<PortInformation> portInformation) {

View File

@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.network.ftp;
/**
@ -10,17 +6,8 @@ package de.muehlencord.shared.network.ftp;
*/
public class FTPConnectionException extends Exception {
/**
*
*/
private static final long serialVersionUID = 4393979078434188521L;
private static final long serialVersionUID = 1001347648193052240L;
/**
* Creates a new instance of
* <code>FTPConnectionException</code> without detail message.
*/
public FTPConnectionException() {
}
/**
* Constructs an instance of

View File

@ -6,17 +6,9 @@ package de.muehlencord.shared.network.http;
*/
public class MessageNotSendException extends Exception {
/**
*
*/
private static final long serialVersionUID = -8959773341187046577L;
private static final long serialVersionUID = -7720277941333614648L;
/**
* Creates a new instance of
* <code>MessageNotSendException</code> without detail message.
*/
public MessageNotSendException() {
}
/**
* Constructs an instance of

View File

@ -3,6 +3,7 @@
*/
package de.muehlencord.shared.network.mail;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@ -213,7 +214,7 @@ public class MailMessage {
* @return the receiver
*/
public List<String> getReceiver() {
return receiver;
return new ArrayList<>(receiver);
}
/**
@ -249,7 +250,7 @@ public class MailMessage {
* @return the ccReceiver
*/
public List<String> getCcReceiver() {
return ccReceiver;
return new ArrayList<>(ccReceiver);
}
/**
@ -276,7 +277,7 @@ public class MailMessage {
* @return the bccReceiver
*/
public List<String> getBccReceiver() {
return bccReceiver;
return new ArrayList<>(bccReceiver);
}
/**

View File

@ -6,17 +6,7 @@ package de.muehlencord.shared.network.mail;
*/
public class MailMessageException extends Exception {
/**
*
*/
private static final long serialVersionUID = 6699249884047524285L;
/**
* Creates a new instance of
* <code>MailMessageException</code> without detail message.
*/
public MailMessageException() {
}
private static final long serialVersionUID = -8147768630871997864L;
/**
* Constructs an instance of

View File

@ -27,32 +27,55 @@ import org.apache.logging.log4j.Logger;
*/
public abstract class MailMessageUtils {
/** the logging object */
/**
* the logging object
*/
private static final Logger LOGGER = LogManager.getLogger(MailMessageUtils.class.getName());
/** content type of mutipart messages - e.g. multipart_alternative or _mixed */
/**
* content type of mutipart messages - e.g. multipart_alternative or _mixed
*/
private static final String CONTENTTYPE_MULTIPART = "multipart/";
/** content type of text messages - like text/plain or text/html */
/**
* content type of text messages - like text/plain or text/html
*/
private static final String CONTENTTYPE_TEXT = "text/";
/** content type of text/plain messages */
/**
* content type of text/plain messages
*/
private static final String CONTENTTYPE_TEXT_PLAIN = "text/plain";
/** content type of text/html messages */
/**
* content type of text/html messages
*/
private static final String CONTENTTYPE_TEXT_HTML = "text/html";
/** content type of application based messages - e.g. application/pdf */
/**
* content type of application based messages - e.g. application/pdf
*/
private static final String CONTENTTYPE_APPLICATION = "application/";
/** content type of application pgp-signature */
/**
* content type of application pgp-signature
*/
private static final String CONTENTTYPE_APPLICATION_PGPSIGNATURE = "application/pgp-signature";
/** content type of embedded message */
/**
* content type of embedded message
*/
private static final String CONTENTTYPE_MESSAGE = "message/";
/** content type of attached images */
/**
* content type of attached images
*/
private static final String CONTENTTYPE_IMAGE = "image/";
/** content type of attached videos */
/**
* content type of attached videos
*/
private static final String CONTENTTYPE_VIDEO = "video/";
/** content type of attached audios */
/**
* content type of attached audios
*/
private static final String CONTENTTYPE_AUDIO = "audio/";
/**
* creates a new instance of MailMessage based on the given javax.mail.Message object
* creates a new instance of MailMessage based on the given
* javax.mail.Message object
*
* @param message the message object to create the message from
* @return the MailMessage object created from the given javax.mail.Message
@ -172,13 +195,10 @@ public abstract class MailMessageUtils {
} catch (MailMessageException | IOException | MessagingException ex) {
throw new MailMessageException("Error while converting nested message. Reason: " + ex.getMessage(), ex);
}
} else if (contentType.contains(CONTENTTYPE_APPLICATION)) {
} else if ((contentType.contains(CONTENTTYPE_APPLICATION)) || (contentType.contains(CONTENTTYPE_TEXT))) {
// message with only attachment
returnMessage = new MailMessage(subject, "", messageId);
LOGGER.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
} else if (contentType.contains(CONTENTTYPE_TEXT)) {
returnMessage = new MailMessage(subject, "", messageId);
LOGGER.debug("Found attachment - not yet supported, skipping"); // TODO add attachment
} else {
String hint = "Unkonwn message format Converting MimeMessage of contentType " + contentType + " not yet implemented.";
@ -187,7 +207,7 @@ public abstract class MailMessageUtils {
LOGGER.debug(mm.getContent());
LOGGER.error(hint);
} catch (IOException | MessagingException ex) {
LOGGER.debug (ex.toString(), ex);
LOGGER.debug(ex.toString(), ex);
LOGGER.error(hint);
}
throw new MailMessageException(hint);
@ -220,8 +240,9 @@ public abstract class MailMessageUtils {
}
/**
* returns the content type based on the content-type header. The messad asures the contentype is selected correctly from the string, including trim and
* tolower case
* returns the content type based on the content-type header. The messad
* asures the contentype is selected correctly from the string, including
* trim and tolower case
*
* @param contentType the contenttype string read from email header
* @return the content type of the email (small letters)
@ -238,8 +259,10 @@ public abstract class MailMessageUtils {
}
/**
* returns the content of the given bodypart which needs to be a text based bodypart The method tries to read the messages as it is. In case of an
* unsupported encoding it reads the message with the default encoding (accepting "ugly" characters)
* returns the content of the given bodypart which needs to be a text based
* bodypart The method tries to read the messages as it is. In case of an
* unsupported encoding it reads the message with the default encoding
* (accepting "ugly" characters)
*
* @param bp the body part to read the content from
* @return the content of the body part
@ -253,7 +276,7 @@ public abstract class MailMessageUtils {
try {
returnValue = bp.getContent().toString();
} catch (java.io.UnsupportedEncodingException ex) {
throw new MessagingException("Cannot read content from bodypart. "+ex.getMessage(), ex);
throw new MessagingException("Cannot read content from bodypart. " + ex.getMessage(), ex);
} catch (java.io.IOException ioex) {
throw new IOException("Cannot read content from bodypart.", ioex);
} catch (MessagingException mex) {
@ -269,8 +292,9 @@ public abstract class MailMessageUtils {
}
/**
* returns the content of the given body part by reading the stream directly. This ommits getting unsupported encoding exceptions, as the content is read
* with the given encoding
* returns the content of the given body part by reading the stream
* directly. This ommits getting unsupported encoding exceptions, as the
* content is read with the given encoding
*
* @param bp the bodypart to read the content from
* @param encoding the encoding to force
@ -332,26 +356,20 @@ public abstract class MailMessageUtils {
}
/**
* returns true, if the contentType string is one of the known attachment types.
* returns true, if the contentType string is one of the known attachment
* types.
*
* @param contentType the contentType to check
* @return true, if the contentType string is one of the known attachment types. False otherwise.
* @return true, if the contentType string is one of the known attachment
* types. False otherwise.
*/
private static boolean isSupportedAttachmentType(String contentType) {
if (contentType.contains(CONTENTTYPE_APPLICATION)) {
return true;
} else if (contentType.contains(CONTENTTYPE_MESSAGE)) {
return true;
} else if (contentType.contains(CONTENTTYPE_TEXT)) {
return true;
} else if (contentType.contains(CONTENTTYPE_IMAGE)) {
return true;
} else if (contentType.contains(CONTENTTYPE_VIDEO)) {
return true;
} else if (contentType.contains(CONTENTTYPE_AUDIO)) {
return true;
} else {
return false;
}
boolean contentTypeOther = contentType.contains(CONTENTTYPE_APPLICATION)
|| (contentType.contains(CONTENTTYPE_MESSAGE))
|| (contentType.contains(CONTENTTYPE_TEXT));
boolean contentTypeMedia = (contentType.contains(CONTENTTYPE_IMAGE))
|| (contentType.contains(CONTENTTYPE_VIDEO))
|| (contentType.contains(CONTENTTYPE_AUDIO));
return contentTypeOther || contentTypeMedia;
}
}

View File

@ -6,17 +6,7 @@ package de.muehlencord.shared.network.mail;
*/
public class MailReaderConfigurationException extends Exception {
/**
*
*/
private static final long serialVersionUID = 3874572911465653501L;
/**
* Creates a new instance of
* <code>MailReaderConfigurationException</code> without detail message.
*/
public MailReaderConfigurationException() {
}
private static final long serialVersionUID = -2079782382789782710L;
/**
* Constructs an instance of

View File

@ -14,7 +14,9 @@ import org.apache.logging.log4j.Logger;
*/
public abstract class MailReaderConfigurationFactory {
/** the logging object */
/**
* the logging object
*/
private final static Logger LOGGER = LogManager.getLogger(MailReaderConfigurationFactory.class);
/**
@ -23,7 +25,8 @@ public abstract class MailReaderConfigurationFactory {
* @param configFile the file to read
* @return the configured MailReaderConfiguration object
*
* @throws MailReaderConfigurationException if the file does not exist or the config cannot be created
* @throws MailReaderConfigurationException if the file does not exist or
* the config cannot be created
*/
public static MailReaderConfiguration getConfiguration(String configFile) throws MailReaderConfigurationException {
File f = new File(configFile);
@ -40,7 +43,9 @@ public abstract class MailReaderConfigurationFactory {
throw new MailReaderConfigurationException("Error while reading config file. Reason: " + ex.getMessage(), ex);
} finally {
try {
if (is != null) {
is.close();
}
} catch (Exception ex) {
LOGGER.error("Error while reading input file.");
LOGGER.debug(StringUtil.getStackTraceString(ex));

View File

@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.network.mail;
/**
@ -10,17 +6,9 @@ package de.muehlencord.shared.network.mail;
*/
public class MailReaderConnectionException extends Exception {
/**
*
*/
private static final long serialVersionUID = -1593741665654202661L;
private static final long serialVersionUID = -3671887060456354046L;
/**
* Creates a new instance of
* <code>MailReaderConnectionException</code> without detail message.
*/
public MailReaderConnectionException() {
}
/**
* Constructs an instance of

View File

@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.network.mail;
/**
@ -10,17 +6,7 @@ package de.muehlencord.shared.network.mail;
*/
public class MailReaderException extends Exception {
/**
*
*/
private static final long serialVersionUID = 4850689622364462635L;
/**
* Creates a new instance of
* <code>MailReaderException</code> without detail message.
*/
public MailReaderException() {
}
private static final long serialVersionUID = -7351011499789639376L;
/**
* Constructs an instance of

View File

@ -2,8 +2,6 @@ package de.muehlencord.shared.network.whois;
import java.util.Locale;
import org.apache.commons.net.whois.WhoisClient;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
*
@ -12,7 +10,7 @@ import org.apache.logging.log4j.Logger;
public class Whois {
/** logger object */
private final static Logger LOGGER = LogManager.getLogger(Whois.class);
// private static final Logger LOGGER = LogManager.getLogger(Whois.class);
/** whoisClient client from commons-net package to execute commands with */
WhoisClient whoisClient;
/** the complete output */

View File

@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.network.whois;
/**
@ -10,12 +6,7 @@ package de.muehlencord.shared.network.whois;
*/
public class WhoisException extends Exception {
/**
* Creates a new instance of
* <code>WhoisException</code> without detail message.
*/
public WhoisException() {
}
private static final long serialVersionUID = 8101593509067902021L;
/**
* Constructs an instance of

View File

@ -1,5 +1,6 @@
package de.muehlencord.shared.network.whois;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@ -27,28 +28,28 @@ public class WhoisInformation {
* @return the network
*/
public List<String> getNetwork() {
return network;
return new ArrayList<>(network);
}
/**
* @param network the network to set
*/
public void setNetwork(List<String> network) {
this.network = network;
this.network = new ArrayList<>(network);
}
/**
* @return the rootNetwork
*/
public List<String> getRootNetwork() {
return rootNetwork;
return new ArrayList<>(rootNetwork);
}
/**
* @param rootNetwork the rootNetwork to set
*/
public void setRootNetwork(List<String> rootNetwork) {
this.rootNetwork = rootNetwork;
this.rootNetwork = new ArrayList<>(rootNetwork);
}
/**

View File

@ -8,7 +8,7 @@ import java.io.InputStream;
*
* @author joern@muehlencord.de
*/
public class BaseTest {
public abstract class BaseTest {
public String readContentFromFile(String name) throws IOException {

View File

@ -10,7 +10,9 @@ import org.apache.commons.codec.binary.Base64;
/**
*
* @author joern@muehlencord.de
* @Deprecated uses old algorithms, do not use this class anylonger
*/
@Deprecated
public abstract class OldPasswordUtil {
/** logging object */

View File

@ -18,11 +18,11 @@ public class PasswordUtil {
private final static int PARALLELIZATION = 1;
private final static int KEY_LENGTH = 32;
private final String SYSTEMSALT;
private final String systemsalt;
public PasswordUtil(String systemSaltBase64Coded) {
// TODO make some tests like lengths etc
this.SYSTEMSALT = systemSaltBase64Coded;
this.systemsalt = systemSaltBase64Coded;
}
public String getHash(String clearPassword) {
@ -33,7 +33,7 @@ public class PasswordUtil {
String userSalt = new String(Base64.encode(userSaltBytes));
// create passwordhash with salt
String passwordHash = getPasswordHash(SYSTEMSALT, userSalt, clearPassword);
String passwordHash = getPasswordHash(systemsalt, userSalt, clearPassword);
StringBuilder sb = new StringBuilder();
sb.append(userSalt);
@ -52,7 +52,7 @@ public class PasswordUtil {
String userSalt = passwordHashWithSalt.substring(0, passwordHashWithSalt.indexOf(":"));
String passwordHash = passwordHashWithSalt.substring(passwordHashWithSalt.indexOf(":")+1);
String validationHash = getPasswordHash(SYSTEMSALT, userSalt, clearPassword);
String validationHash = getPasswordHash(systemsalt, userSalt, clearPassword);
return validationHash.equals(passwordHash);
}

View File

@ -4,6 +4,7 @@ import java.net.Authenticator;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@ -50,13 +51,13 @@ public class SPContext {
}
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
public void checkClientTrusted(X509Certificate[] certs, String authType) {
// trust all SSLs, do not check
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
public void checkServerTrusted(X509Certificate[] certs, String authType) {
// trust all SSLs, do not check
}
}};
// Install the all-trusting trust manager

View File

@ -9,36 +9,14 @@ import java.util.Date;
*/
public class SPHelper {
private static final SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd");
// private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
/* -- Format for Date Only Field -- */
public static String toSPDate(Date d) {
public static synchronized String toSPDate(Date d) {
SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd");
if (d == null) {
return "";
}
String result;
synchronized (dateOnlyFormat) {
result = dateOnlyFormat.format(d);
return dateOnlyFormat.format(d);
}
return result;
}
/* -- Format for DateTime Field -- */
/*
private static String toSPDateAndTime(Date d) {
if (d == null) {
return "";
}
String result;
synchronized (dateTimeFormat) {
result = dateTimeFormat.format(d);
}
return result;
}
*/
}

View File

@ -38,7 +38,7 @@ public abstract class SPJaxbObject<T> extends AbstractSpJaxbObject {
+ ":de.muehlencord.shared.sharepoint.api.usergroup"; //
/** the JAX-B context to use */
private static JAXBContext jaxbContext = null;
private static volatile JAXBContext jaxbContext = null;
/** the value object */
protected T value;

View File

@ -35,10 +35,8 @@ public class SPValidationEventHandler implements ValidationEventHandler {
switch (event.getSeverity()) {
case ValidationEvent.WARNING:
return true; // continue after warinings
case ValidationEvent.ERROR:
return false; // terminate after errors
case ValidationEvent.FATAL_ERROR:
return false; // terminate after fatal errors
case ValidationEvent.ERROR: // terminate after errors
case ValidationEvent.FATAL_ERROR: // terminate after fatal errors
default:
return false;
}

View File

@ -38,9 +38,7 @@ public class SPUser extends SPJaxbObject<User> {
returnValue = getValue().login;
}
if (returnValue == null) {
return null;
} else if (returnValue.equals("")) {
if ((returnValue == null) || (returnValue.equals (""))) {
return null;
} else {
return returnValue.substring(7); // drop [i:0#.w|

View File

@ -17,7 +17,7 @@ import org.junit.Before;
*
* @author jomu
*/
public class BaseTest {
public abstract class BaseTest {
protected SPContext context = null;

View File

@ -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);

View File

@ -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,

View File

@ -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;

View File

@ -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 {