OpenCSV: How to create CSV file from POJO with custom column headers and custom column positions?

I’ve had similar problem. AFAIK there is no build-in functionality in OpenCSV that will allow to write bean to CSV with custom column names and ordering. There are two main MappingStrategyies that are available in OpenCSV out of the box: HeaderColumnNameMappingStrategy: that allows to map CVS file columns to bean fields based on custom name; …

Read more

Returning an array without assign to a variable

You still need to create the array, even if you do not assign it to a variable. Try this: public int[] getData() { return new int[] {a,b,c,d}; } Your code sample did not work because the compiler, for one thing, still needs to know what type you are attempting to create via static initialization {}.

Try catch in a JUnit test

Since Exception is a checked exception, you either: Have to catch the exception in a try…catch statement, or Declare the exception to be thrown in the method itself. What you have up there works fine, but my personal preference is to declare the exception to be thrown. This way, if an exception I’m not expecting …

Read more

Java/ImageIO getting image dimensions without reading the entire file?

try(ImageInputStream in = ImageIO.createImageInputStream(resourceFile)){ final Iterator<ImageReader> readers = ImageIO.getImageReaders(in); if (readers.hasNext()) { ImageReader reader = readers.next(); try { reader.setInput(in); return new Dimension(reader.getWidth(0), reader.getHeight(0)); } finally { reader.dispose(); } } } Thanks to sfussenegger for the suggestion

How to WhiteList app in Doze mode Android 6.0

Add permission <uses-permission android:name=”android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS”/> request whitelist your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(); String packageName = getPackageName(); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); if (!pm.isIgnoringBatteryOptimizations(packageName)) { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse(“package:” + packageName)); startActivity(intent); } }