Pesquisar neste blogue

Mostrar mensagens com a etiqueta java. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta java. Mostrar todas as mensagens

segunda-feira, 17 de dezembro de 2018

CSV handling in Java

These past days i've been trying to load CSV files in Java. Used opencsv with some degree with success, however some fields were still misinterpreted .
Next an old friend by name of FasterXML/jackson came to the rescue, however i was still having some issues.
Last but not least on stackoverflow.com (where else) i came across https://simpleflatmapper.org/ and with something like:


CsvParser.separator(';')

   .mapTo(MyClass.class)

   .headers("my","headers","list")

   .iterator(new File(filepath));


I was up and running .

Note : If you find MalformedInputException check if your input is UTF-8 , more info here  http://biercoff.com/malformedinputexception-input-length-1-exception-solution-for-scala-and-java/

terça-feira, 13 de novembro de 2018

JAVAMAIL: Cleaning temporary files used as attachments

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
private static void cleanAttachments(MimeMessage message) {
   try {
 if (message.getContent() != null) {
  MimeMultipart multi = (MimeMultipart) message.getContent();
  for (int j = 0; j < multi.getCount(); j++) {
   BodyPart bodyPart = multi.getBodyPart(j);
   if (bodyPart.getDataHandler().getDataSource()
     instanceof FileDataSource) {
    FileDataSource f = (FileDataSource)
    bodyPart.getDataHandler().getDataSource();
    f.getFile().delete();
   }
  }
 }
  } catch (MessagingException e) {
  e.printStackTrace();
  } catch (IOException e) {
  e.printStackTrace();
  }
}

For when you use File.createTempFile  to support the attachments of a mail message and cannot use deleteOnExit because the JVM will not exit.
Something i saw myself needing.

All the best.

quarta-feira, 10 de fevereiro de 2016

Quartz Scheduler

A while back i had to work with Quartz (the scheduler) - Quartz - not to be confused with - Quartz (graphics_layer)  and i would like to share a website that helped me CronMaker.
Thanks to who had the work of making my life easier :)

terça-feira, 22 de dezembro de 2015

Struts 2 and TLD issues.


According to TLD or attribute directive in tag file, attribute value does not accept any expressions

I have been rather plagued by this error on the last few days when using Struts2 till. By chance i came across https://almeidamike.wordpress.com/2010/03/12/struts-solving-according-to-tld-or-attribute-directive-in-tag-file-attribute-value-does-not-accept-any-expressions/ .
So if you are having some difficulties accessing parameters of the request or other values be sure to enable debug as specified in https://struts.apache.org/docs/debugging-struts.html and find the correct path to your value.
Credits to the owner of https://almeidamike.wordpress.com/author/almeidamike/.

Examples:
${someField} becomes %{#attr.someField}. Acessing request parameters would be for instance  %{#parameters.someField}.

quarta-feira, 1 de julho de 2015

Before delving into Odoo i would like to share a project that has saved my life a couple of times - signtester .
If you need to sign (re-sign) several jar files take a look at it :)