} // end if: compress
// Else, don't compress. Better not to use streams at all then.
- else {
- boolean breakLines = (options & DO_BREAK_LINES) != 0;
-
- //int len43 = len * 4 / 3;
- //byte[] outBuff = new byte[ ( len43 ) // Main 4:3
- // + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding
- // + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines
- // Try to determine more precisely how big the array needs to be.
- // If we get it right, we don't have to do an array copy, and
- // we save a bunch of memory.
- int encLen = ( len / 3 ) * 4 + ( len % 3 > 0 ? 4 : 0 ); // Bytes needed for actual encoding
- if( breakLines ){
- encLen += encLen / MAX_LINE_LENGTH; // Plus extra newline characters
- }
- byte[] outBuff = new byte[ encLen ];
+ boolean breakLines = (options & DO_BREAK_LINES) != 0;
+
+ //int len43 = len * 4 / 3;
+ //byte[] outBuff = new byte[ ( len43 ) // Main 4:3
+ // + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding
+ // + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines
+ // Try to determine more precisely how big the array needs to be.
+ // If we get it right, we don't have to do an array copy, and
+ // we save a bunch of memory.
+ int encLen = ( len / 3 ) * 4 + ( len % 3 > 0 ? 4 : 0 ); // Bytes needed for actual encoding
+ if( breakLines ){
+ encLen += encLen / MAX_LINE_LENGTH; // Plus extra newline characters
+ }
+ byte[] outBuff = new byte[ encLen ];
- int d = 0;
- int e = 0;
- int len2 = len - 2;
- int lineLength = 0;
- for( ; d < len2; d+=3, e+=4 ) {
- encode3to4( source, d+off, 3, outBuff, e, options );
+ int d = 0;
+ int e = 0;
+ int len2 = len - 2;
+ int lineLength = 0;
+ for( ; d < len2; d+=3, e+=4 ) {
+ encode3to4( source, d+off, 3, outBuff, e, options );
- lineLength += 4;
- if( breakLines && lineLength >= MAX_LINE_LENGTH )
- {
- outBuff[e+4] = NEW_LINE;
- e++;
- lineLength = 0;
- } // end if: end of line
- } // en dfor: each piece of array
-
- if( d < len ) {
- encode3to4( source, d+off, len - d, outBuff, e, options );
- e += 4;
- } // end if: some padding needed
-
-
- // Only resize array if we didn't guess it right.
- if( e <= outBuff.length - 1 ){
- // If breaking lines and the last byte falls right at
- // the line length (76 bytes per line), there will be
- // one extra byte, and the array will need to be resized.
- // Not too bad of an estimate on array size, I'd say.
- byte[] finalOut = new byte[e];
- System.arraycopy(outBuff,0, finalOut,0,e);
- //System.err.println("Having to resize array from " + outBuff.length + " to " + e );
- return finalOut;
- } else {
- //System.err.println("No need to resize array.");
- return outBuff;
- }
+ lineLength += 4;
+ if( breakLines && lineLength >= MAX_LINE_LENGTH )
+ {
+ outBuff[e+4] = NEW_LINE;
+ e++;
+ lineLength = 0;
+ } // end if: end of line
+ } // en dfor: each piece of array
+
+ if( d < len ) {
+ encode3to4( source, d+off, len - d, outBuff, e, options );
+ e += 4;
+ } // end if: some padding needed
+
+
+ // Only resize array if we didn't guess it right.
+ if( e <= outBuff.length - 1 ){
+ // If breaking lines and the last byte falls right at
+ // the line length (76 bytes per line), there will be
+ // one extra byte, and the array will need to be resized.
+ // Not too bad of an estimate on array size, I'd say.
+ byte[] finalOut = new byte[e];
+ System.arraycopy(outBuff,0, finalOut,0,e);
+ //System.err.println("Having to resize array from " + outBuff.length + " to " + e );
+ return finalOut;
+ }
- } // end else: don't compress
-
+ //System.err.println("No need to resize array.");
+ return outBuff;
} // end encodeBytesToBytes
* @throws java.io.IOException If bogus characters exist in source data
* @since 1.3
*/
- public static byte[] decode( byte[] source, int off, int len, int options )
+ @SuppressWarnings("cast")
+ public static byte[] decode( byte[] source, int off, int len, int options )
throws java.io.IOException {
// Lots of error checking and exception throwing
boolean dontGunzip = (options & DONT_GUNZIP) != 0;
if( (bytes != null) && (bytes.length >= 4) && (!dontGunzip) ) {
- int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
+ @SuppressWarnings("cast")
+ int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) {
java.io.ByteArrayInputStream bais = null;
java.util.zip.GZIPInputStream gzis = null;
Class c = Class.forName(streamClass.getName(), false, loader);
if( c == null ){
return super.resolveClass(streamClass);
- } else {
- return c; // Class loader knows of this class.
- } // end else: not null
+ }
+ return c; // Class loader knows of this class.
} // end resolveClass
}; // end ois
} // end else: no custom class loader
lineLength = 0;
return '\n';
} // end if
- else {
- lineLength++; // This isn't important when decoding
- // but throwing an extra "if" seems
- // just as wasteful.
-
- int b = buffer[ position++ ];
+ lineLength++; // This isn't important when decoding
+ // but throwing an extra "if" seems
+ // just as wasteful.
+
+ int b = buffer[ position++ ];
- if( position >= bufferLength ) {
- position = -1;
- } // end if: end
+ if( position >= bufferLength ) {
+ position = -1;
+ } // end if: end
- return b & 0xFF; // This is how you "cast" a byte that's
- // intended to be unsigned.
- } // end else
+ return b & 0xFF; // This is how you "cast" a byte that's
+ // intended to be unsigned.
} // end if: position >= 0
- // Else error
- else {
- throw new java.io.IOException( "Error in Base64 code reading stream." );
- } // end else
+ throw new java.io.IOException( "Error in Base64 code reading stream." );
} // end read
public String getText() {
if (text == null) {
if (image == null || size == null || size.width == 0
- || size.height == 0)
+ || size.height == 0) {
return "";
+ }
int mult = 1;
- if (mode == Mode.DOUBLE_RESOLUTION || mode == Mode.DOUBLE_DITHERING)
+ if (mode == Mode.DOUBLE_RESOLUTION || mode == Mode.DOUBLE_DITHERING) {
mult = 2;
+ }
int w = size.width * mult;
int h = size.height * mult;
}
if (gfx.drawImage(image, x, y, w, h, new ImageObserver() {
+ @Override
public boolean imageUpdate(Image img, int infoflags, int x,
int y, int width, int height) {
ImageText.this.ready = true;
StringBuilder builder = new StringBuilder();
for (int row = 0; row < buff.getHeight(); row += mult) {
- if (row > 0)
+ if (row > 0) {
builder.append('\n');
+ }
for (int col = 0; col < buff.getWidth(); col += mult) {
if (mult == 1) {
private char getBlockChar(int upperleft, int upperright, int lowerleft,
int lowerright, boolean dithering) {
int choice = 0;
- if (getBrightness(upperleft) > 0.5f)
+
+ if (getBrightness(upperleft) > 0.5f) {
choice += 1;
- if (getBrightness(upperright) > 0.5f)
+ }
+ if (getBrightness(upperright) > 0.5f) {
choice += 2;
- if (getBrightness(lowerleft) > 0.5f)
+ }
+ if (getBrightness(lowerleft) > 0.5f) {
choice += 4;
- if (getBrightness(lowerright) > 0.5f)
+ }
+ if (getBrightness(lowerright) > 0.5f) {
choice += 8;
+ }
switch (choice) {
case 0:
avg /= 4;
return getDitheringChar(avg, " â–‘â–’â–“â–ˆ");
- } else {
- return 'â–ˆ';
}
+
+ return 'â–ˆ';
}
return ' ';
* @return the brightness to sue for computations
*/
private float getBrightness(int argb) {
- if (invert)
+ if (invert) {
return 1 - rgb2hsb(argb, tmp)[2];
+ }
+
return rgb2hsb(argb, tmp)[2];
}
g = ((argb & 0x0000ff00) >> 8);
b = ((argb & 0x000000ff));
- if (array == null)
+ if (array == null) {
array = new float[4];
+ }
+
Color.RGBtoHSB(r, g, b, array);
array[3] = a;
* the progress to set
*/
private void setTotalProgress(Progress pg, String name, int progress) {
+ // TODO: name is not used... and this is probably a bug in this case
synchronized (getLock()) {
progress = Math.max(min, progress);
progress = Math.min(max, progress);
}
progress.addProgressListener(new ProgressListener() {
+ @Override
public void progress(Progress pg, String name) {
synchronized (getLock()) {
double total = ((double) localProgress) / (max - min);
return new Version(version);
}
+ @Override
public int compareTo(Version o) {
if (equals(o)) {
return 0;
for (Field field : type.getDeclaredFields()) {
Meta meta = field.getAnnotation(Meta.class);
if (meta != null) {
- E id = E.valueOf(type, field.getName());
+ E id = Enum.valueOf(type, field.getName());
String info = getMetaInfo(meta);
if (info != null) {
}
}
}
-
+
/**
* Take a snapshot of the changes in memory in this {@link Bundle} made by
* the "set" methods ( {@link Bundle#setString(Enum, String)}...) at the
file = new File(dir, name + loc + ".properties");
if (file.exists()) {
break;
- } else {
- file = null;
}
+
+ file = null;
}
return file;
* the resources.
*
* @author niki
- *
+ *
*/
class FixedResourceBundleControl extends Control {
@Override
}
}
} else {
- if (stream == null)
- stream = loader.getResourceAsStream(resourceName);
+ stream = loader.getResourceAsStream(resourceName);
}
+
if (stream != null) {
try {
// This line is changed to make it to read properties files
result = null;
}
- if (values != null && values.length > 0 && result != null)
+ if (values != null && values.length > 0 && result != null) {
return String.format(locale, result, values);
- else
- return result;
+ }
+
+ return result;
}
/**
}
final Enumeration<? extends ZipEntry> e = zf.entries();
while (e.hasMoreElements()) {
- final ZipEntry ze = (ZipEntry) e.nextElement();
+ final ZipEntry ze = e.nextElement();
final String fileName = ze.getName();
final boolean accept = pattern.matcher(fileName).matches();
if (accept) {
public void connectAsync() {
new Thread(new Runnable() {
+ @Override
public void run() {
connect();
}
return new Importer().read(str).getValue();
}
- protected void onClientVersionReceived(Version clientVersion) {
-
+ /**
+ * Handler called when the client {@link Version} is received.
+ *
+ * @param clientVersion
+ * the client {@link Version}
+ */
+ protected void onClientVersionReceived(
+ @SuppressWarnings("unused") Version clientVersion) {
}
- protected void onError(Exception e) {
-
+ /**
+ * Handler called when an unexpected error occurs in the code.
+ *
+ * @param e
+ * the exception that occurred
+ */
+ protected void onError(@SuppressWarnings("unused") Exception e) {
}
// \n included in line, but not in rep (also, server never get anything)
if (server) {
out.flush();
return null;
- } else {
- contentToSend = true;
- return flushString();
}
+
+ contentToSend = true;
+ return flushString();
}
}
}
return line;
- } else {
- return null;
}
+
+ return null;
}
}
}
\ No newline at end of file
if (zip) {
return "ZIP:" + StringUtils.zip64(builder.toString());
- } else {
- return builder.toString();
}
+
+ return builder.toString();
}
/**
String type = CustomSerializer.typeOf(encodedValue);
if (customTypes.containsKey(type)) {
return customTypes.get(type).decode(encodedValue);
- } else {
- throw new UnknownFormatConversionException(
- "Unknown custom type: " + type);
}
+ throw new UnknownFormatConversionException("Unknown custom type: "
+ + type);
} else if (encodedValue.equals("NULL") || encodedValue.equals("null")) {
return null;
} else if (encodedValue.endsWith("\"")) {
abstract public class Server implements Runnable {
static private final String[] ANON_CIPHERS = getAnonCiphers();
- private Version serverVersion = new Version();
private int port;
private boolean ssl;
private ServerSocket ss;
private Object lock = new Object();
private Object counterLock = new Object();
- public Server(Version version, int port, boolean ssl) throws IOException {
- this.serverVersion = version;
+ @Deprecated
+ public Server(@SuppressWarnings("unused") Version notUsed, int port,
+ boolean ssl) throws IOException {
+ this(port, ssl);
+ }
+
+ public Server(int port, boolean ssl) throws IOException {
this.port = port;
this.ssl = ssl;
this.ss = createSocketServer(port, ssl);
stop(timeout);
} else {
new Thread(new Runnable() {
+ @Override
public void run() {
stop(timeout);
}
}
}
+ @Override
public void run() {
try {
while (started && !exiting) {
} finally {
count(-1);
}
- };
+ }
@Override
protected void onClientVersionReceived(Version clientVersion) {
this.clientVersion = clientVersion;
- };
+ }
}.connectAsync();
}
final JButton b = new JButton("Set pg to 10%");
b.addActionListener(new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
switch (i) {
case 0:
public void test() throws Exception {
Progress p = new Progress();
p.addProgressListener(new Progress.ProgressListener() {
+ @Override
public void progress(Progress progress, String name) {
pg = progress.getProgress();
}
p.addProgress(child2, 50);
p.addProgressListener(new Progress.ProgressListener() {
+ @Override
public void progress(Progress progress, String name) {
pg = p.getProgress();
}
p.addProgress(child2, 500);
p.addProgressListener(new Progress.ProgressListener() {
+ @Override
public void progress(Progress progress, String name) {
pg = p.getProgress();
}
// 200 = local progress
p.addProgressListener(new Progress.ProgressListener() {
+ @Override
public void progress(Progress progress, String name) {
pg = p.getProgress();
}
child111.addProgress(child1115, 20);
p.addProgressListener(new Progress.ProgressListener() {
+ @Override
public void progress(Progress progress, String name) {
pg = p.getProgress();
}
p.addProgress(child2, 100);
p.addProgressListener(new Progress.ProgressListener() {
+ @Override
public void progress(Progress progress, String name) {
int now = p.getProgress();
if (now < pg) {
for (int i = 0; i <= 100; i++) {
final int step = i;
new Thread(new Runnable() {
+ @Override
public void run() {
synchronized (lock1) {
if (step > currentStep1) {
}).start();
new Thread(new Runnable() {
+ @Override
public void run() {
synchronized (lock2) {
if (step > currentStep2) {
import be.nikiroo.utils.serial.Server;
class SerialTest extends TestLauncher {
+ @SuppressWarnings("unused")
private void not_used() {
// TODO: test Server ; but this will at least help dependency checking
try {
- Server server = new Server(null, 0, false) {
+ Server server = new Server(0, false) {
@Override
protected Object onRequest(ConnectActionServer action,
Version clientVersion, Object data) throws Exception {
if (errorMessage == null) {
throw new AssertException(generateAssertMessage(expected,
actual));
- } else {
- throw new AssertException(errorMessage, new AssertException(
- generateAssertMessage(expected, actual)));
}
+
+ throw new AssertException(errorMessage, new AssertException(
+ generateAssertMessage(expected, actual)));
}
}
if (errorMessage == null) {
throw new AssertException(defaultReason);
- } else {
- throw new AssertException(errorMessage, new AssertException(
- defaultReason));
}
+
+ throw new AssertException(errorMessage, new AssertException(
+ defaultReason));
}
}
import javax.swing.border.EmptyBorder;
import be.nikiroo.utils.resources.Bundle;
-import be.nikiroo.utils.resources.TransBundle;
/**
* A configuration panel for a {@link Bundle}.
}
main.add(createButton("Reset", new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
for (ConfigItem<E> item : items) {
item.reload();
}));
main.add(createButton("Default", new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
Object snap = bundle.takeSnapshot();
bundle.reload(true);
}));
main.add(createButton("Save", new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
for (ConfigItem<E> item : items) {
item.save();
this.pg = pg;
SwingUtilities.invokeLater(new Runnable() {
+ @Override
public void run() {
if (pg != null) {
final JProgressBar bar = new JProgressBar();
bar.setString(pg.getName());
pg.addProgressListener(new Progress.ProgressListener() {
+ @Override
public void progress(Progress progress, String name) {
final Progress.ProgressListener l = this;
SwingUtilities.invokeLater(new Runnable() {
+ @Override
public void run() {
Map<Progress, JProgressBar> newBars = new HashMap<Progress, JProgressBar>();
newBars.put(pg, bar);