Skip to content

Commit

Permalink
Fix some typos, wordings, tests, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
centic9 committed Dec 17, 2017
1 parent 1b53fcb commit a0aaf8c
Show file tree
Hide file tree
Showing 33 changed files with 279 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Map;
import java.util.Map.Entry;


/**
* Some helper methods related to Maps, e.g. sorting by value.
*
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/dstadler/commons/dynatrace/Measure.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Helper class to handle measures together with their dynamic measure values locally.
*
* These are then passed on to the Dynatrace measure interface.
* These are then passed on to the Dynatrace AppMon measure interface.
*
* This class supports only one type of dynamic measure which can have a number of
* values reported for different occurrences.
Expand Down Expand Up @@ -65,7 +65,6 @@ public Map<String, Double> getDynamicMeasures() {
return adjustedMap;
}

@SuppressWarnings("ResultOfMethodCallIgnored")
public void addDynamicMeasure(String dynamic, double lvalue) {
checkNotNull(dynamic,
"Cannot add a dynamic measure value when the key of the dynamic measure is null");
Expand All @@ -87,10 +86,9 @@ public void addValue(double lvalue) {
value+=lvalue;
}

private static <T> T checkNotNull(T reference, Object errorMessage) {
private static void checkNotNull(Object reference, Object errorMessage) {
if (reference == null) {
throw new NullPointerException(String.valueOf(errorMessage));
}
return reference;
}
}
1 change: 0 additions & 1 deletion src/main/java/org/dstadler/commons/email/EmailConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.logging.Logger;


/**
* Configuration object for all properties necessary to send an email.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.lang3.builder.ToStringBuilder;


/**
* Configuration object for the properties that are necessary to configure
* an SMTP email server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,57 @@
* @author dominik.stadler
*/
public class BufferingLogOutputStream extends LogOutputStream {
private final static Logger log = LoggerFactory.make();
private final static Logger log = LoggerFactory.make();

/**
* The max number of characters of output that are collected from the external application before reporting them to our log-system.
*
* A final flush is done at the end to capture all output.
*/
private static final int LOG_FLUSH_LIMIT = 5000;
/**
* The max number of characters of output that are collected from the external application before reporting them to our log-system.
*
* A final flush is done at the end to capture all output.
*/
private static final int LOG_FLUSH_LIMIT = 5000;

private static final int LOG_FLUSH_TIME_LIMIT_SEC = 5;
private static final int LOG_FLUSH_TIME_LIMIT_SEC = 5;

/**
* Buffer for output from the external application. Constrained by {@link #LOG_FLUSH_LIMIT}
*/
private final StringBuilder logBuffer = new StringBuilder();
/**
* Buffer for output from the external application. Constrained by {@link #LOG_FLUSH_LIMIT}
*/
private final StringBuilder logBuffer = new StringBuilder();

private long lastFlush = System.currentTimeMillis();
private long lastFlush = System.currentTimeMillis();

@Override
protected void processLine(String line, int level) {
synchronized (logBuffer) {
if(line != null && line.length() > 0) {
logBuffer.append(line).append("\n");
@Override
protected void processLine(String line, int level) {
synchronized (logBuffer) {
if(line != null && line.length() > 0) {
logBuffer.append(line).append("\n");

if(logBuffer.length() > LOG_FLUSH_LIMIT ||
lastFlush < (System.currentTimeMillis() - 1000*LOG_FLUSH_TIME_LIMIT_SEC)) {
log.info(logBuffer.toString());
logBuffer.setLength(0);
lastFlush = System.currentTimeMillis();
}
}
}
}
if(logBuffer.length() > LOG_FLUSH_LIMIT ||
lastFlush < (System.currentTimeMillis() - 1000*LOG_FLUSH_TIME_LIMIT_SEC)) {
log.info(logBuffer.toString());
logBuffer.setLength(0);
lastFlush = System.currentTimeMillis();
}
}
}
}

/**
* Flush any pending data in the {@link #logBuffer}
* @throws IOException If closing the stream fails.
*/
@Override
public void close() throws IOException {
// first close the parent so we get all remaining data
super.close();
/**
* Flush any pending data in the {@link #logBuffer}
*
* @throws IOException If closing the stream fails.
*/
@Override
public void close() throws IOException {
// first close the parent so we get all remaining data
super.close();

// then ensure that any remaining buffer is logged
synchronized (logBuffer) {
if(logBuffer.length() > 0) {
log.info(logBuffer.toString());
logBuffer.setLength(0);
lastFlush = System.currentTimeMillis();
}
}
}
// then ensure that any remaining buffer is logged
synchronized (logBuffer) {
if(logBuffer.length() > 0) {
log.info(logBuffer.toString());
logBuffer.setLength(0);
lastFlush = System.currentTimeMillis();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.apache.commons.exec.PumpStreamHandler;
import org.dstadler.commons.logging.jdk.LoggerFactory;


/**
* Helper class which provides convenience support for execution of commandline processes via commons-exec.
*
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/dstadler/commons/graphviz/DotUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Simple utility methods to run the dot-tool from Graphviz on a file.
*
* @author dominik.stadler
*
*/
public class DotUtils {
public static String DOT_EXE = SystemUtils.IS_OS_WINDOWS ? "C:\\cygwin\\bin\\dot.exe" : "/usr/bin/dot";
Expand Down Expand Up @@ -72,18 +71,18 @@ public static void writeHeader(Writer writer, int dpi, String rankdir, String id
// add ...

// DPI and Rankdir
String header = "digraph " + id + " {\n";
StringBuilder header = new StringBuilder("digraph " + id + " {\n");
if (dpi > 0) {
header += "dpi=" + dpi + ";\n";
header.append("dpi=").append(dpi).append(";\n");
}
header += "rankdir=" + (StringUtils.isNotBlank(rankdir) ? rankdir : "LR") + ";\n";
header.append("rankdir=").append(StringUtils.isNotBlank(rankdir) ? rankdir : "LR").append(";\n");

// Additional lines
for (String line : attribLines) {
line = line.trim();
header += line + (line.endsWith(";") ? "\n" : ";\n");
header.append(line).append(line.endsWith(";") ? "\n" : ";\n");
}
DotUtils.writeln(writer, header);
DotUtils.writeln(writer, header.toString());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
public class HttpClientWrapper implements Closeable {
private final static Logger log = LoggerFactory.make();

private final CredentialsProvider credsProvider = new BasicCredentialsProvider();
private final CloseableHttpClient httpClient;

private final int timeoutMs;
Expand All @@ -72,6 +71,7 @@ public class HttpClientWrapper implements Closeable {
public HttpClientWrapper(String user, String password, int timeoutMs) {
super();

CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(null, -1),
new UsernamePasswordCredentials(user, password));
Expand Down
62 changes: 35 additions & 27 deletions src/main/java/org/dstadler/commons/http/NanoHTTPD.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,9 @@ public void stop()
}
}


/**
* Starts as a standalone file server and waits for Enter.
* @throws IOException
* @throws IOException If starting the web-server fails.
*/
public static void main( String[] args ) throws IOException
{
Expand Down Expand Up @@ -426,18 +425,19 @@ public void run()
{
sendError( HTTP_INTERNALERROR, msg);
}
catch ( Throwable t ) {} // NOPMD - imported code
catch ( Throwable t ) { // NOPMD - imported code
// imported code
}
} finally {
in.close();
}
}
catch ( IOException ioe )
{
try
{
sendError( HTTP_INTERNALERROR, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
catch ( IOException ioe ) {
try {
sendError(HTTP_INTERNALERROR, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
} catch (Throwable t) { // NOPMD - imported code
// imported code
}
catch ( Throwable t ) {} // NOPMD - imported code
}
}

Expand All @@ -457,7 +457,9 @@ private void handlePOST(BufferedReader in, Properties parms, Properties header)
if (contentLength != null)
{
try { size = Integer.parseInt(contentLength); }
catch (NumberFormatException ex) {} // NOPMD - imported code
catch (NumberFormatException ex) { // NOPMD - imported code
// imported code
}
}
StringBuilder postLine = new StringBuilder();
char buf[] = new char[512];
Expand Down Expand Up @@ -596,7 +598,11 @@ private void sendResponse( String status, String mime, Properties header, InputS
catch( IOException ioe )
{
// Couldn't write? No can do.
try { mySocket.close(); } catch( Throwable t ) {} // NOPMD - imported code
try {
mySocket.close();
} catch( Throwable t ) { // NOPMD - imported code
// imported code
}
}
}

Expand All @@ -618,9 +624,12 @@ private String encodeUri( String uri )
newUri.append('/');
} else if ( tok.equals( " " )) {
newUri.append("%20");
} else
{
try { newUri.append(URLEncoder.encode( tok, "UTF-8" )); } catch ( UnsupportedEncodingException uee ) {} // NOPMD - imported code
} else {
try {
newUri.append(URLEncoder.encode( tok, "UTF-8" ));
} catch ( UnsupportedEncodingException uee ) { // NOPMD - imported code
// imported code
}
}
}
return newUri.toString();
Expand Down Expand Up @@ -756,14 +765,14 @@ private String getMIMEType(File f) throws IOException {

private String createDirListing(String uri, File f) {
String[] files = f.list();
String msg = "<html><body><h1>Directory " + uri + "</h1><br/>";
StringBuilder msg = new StringBuilder("<html><body><h1>Directory " + uri + "</h1><br/>");

if ( uri.length() > 1 )
{
String u = uri.substring( 0, uri.length()-1 );
int slash = u.lastIndexOf( '/' );
if ( slash >= 0 && slash < u.length()) {
msg += "<b><a href=\"" + uri.substring(0, slash+1) + "\">..</a></b><br/>";
msg.append("<b><a href=\"").append(uri.substring(0, slash + 1)).append("\">..</a></b><br/>");
}
}

Expand All @@ -773,34 +782,33 @@ private String createDirListing(String uri, File f) {
boolean dir = curFile.isDirectory();
if ( dir )
{
msg += "<b>";
msg.append("<b>");
files[i] += '/';
}

msg += "<a href=\"" + encodeUri( uri + files[i] ) + "\">" +
files[i] + "</a>";
msg.append("<a href=\"").append(encodeUri(uri + files[i])).append("\">").append(files[i]).append("</a>");

// Show file size
if ( curFile.isFile())
{
long len = curFile.length();
msg += " &nbsp;<font size=2>(";
msg.append(" &nbsp;<font size=2>(");
if ( len < 1024 ) {
msg += curFile.length() + " bytes";
msg.append(curFile.length()).append(" bytes");
} else if ( len < 1024 * 1024 ) {
msg += curFile.length()/1024 + "." + (curFile.length()%1024/10%100) + " KB";
msg.append(curFile.length() / 1024).append(".").append(curFile.length() % 1024 / 10 % 100).append(" KB");
} else {
msg += curFile.length()/(1024*1024) + "." + curFile.length()%(1024*1024)/10%100 + " MB";
msg.append(curFile.length() / (1024 * 1024)).append(".").append(curFile.length() % (1024 * 1024) / 10 % 100).append(" MB");
}

msg += ")</font>";
msg.append(")</font>");
}
msg += "<br/>";
msg.append("<br/>");
if ( dir ) {
msg += "</b>";
msg.append("</b>");
}
}
return msg;
return msg.toString();
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/dstadler/commons/io/TailInputStream.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
/*
* Taken from http://www.java2s.com/Open-Source/Java-Document/IDE-Eclipse/Eclipse-plug-in-development/org/eclipse/pde/internal/runtime/logview/TailInputStream.java.htm
*/
/*******************************************************************************

/*
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -37,10 +38,10 @@ public TailInputStream(File file, long maxLength)
skipHead(file);
}

private final void skipHead(File file) throws IOException {
private void skipHead(File file) throws IOException {
if (file.length() > fTail) {
fRaf.seek(file.length() - fTail);
// skip bytes until a new line to be sure we start from a beginnng of valid UTF-8 character
// skip bytes until a new line to be sure we start from a beginning of valid UTF-8 character
int c = read();
while (c != '\n' && c != '\r' && c != -1) {
c = read();
Expand Down
Loading

0 comments on commit a0aaf8c

Please sign in to comment.