Hi Cossaer,

when I pasted your test function into a test case I realized that you seem
to work with an older Simple API, as

search.getCurrentItem();

does no longer exist. Have you tried with building it with the latest
sources?

The problem is obvious part of the Simple API, which I am personally not
using and which originally was donated by IBM.

I therefore suggest to update to the latest sources and if the error still
occurs give the common memory tooling a try, for instance:
http://developerblog.redhat.com/2014/08/14/find-fix-memory-leaks-java-application/

I am curious on your results..

Best regards,
Svante




On Tue, Jan 5, 2016 at 2:06 PM, Cossaer Filip <[email protected]> wrote:

> Hi there,
>
>
>
> I came upon the following situation when I used this method, I have a
> OutOfMemory error.
>
> When I do remove the usage of this method, everything is oke.
>
> TextNavigation or TextSelection doesn’t implement the Closeable interface
> so I normally don’t have to close them.
>
>
>
> private void replace(String searchField, String data, OdfTextDocument
> document) throws InvalidNavigationException {
>
>         TextNavigation search = new TextNavigation(searchField, document);
>
>         while (search.hasNext()) {
>
>             TextSelection item = (TextSelection) search.getCurrentItem();
>
>             item.replaceWith(data);
>
>         }
>
>     }
>
>
>
> To give a situation, I’m building PDF’s(approx. 30k) from an ODT template
> (already byte[] in code)
>
> We need to inject some data into the template and then we save it to the
> DB.
>
>
>
> Can you confirm this is a memory leak in your part or the issue is with me?
>
>
>
> The usage is in this part :
>
>
>
>
>
> /**
>
>      * Creates all the bulletins from the given templates, with data
> stored in the extractor.
>
>      *
>
>      * @throws Exception => createPdf(Bulletin bulletin, String[] data)
> throws Exception so can't be more specified here.
>
>      */
>
>     public void createBulletins() throws Exception {
>
>         Map<Bulletin, byte[]> bulletins = Maps.newHashMap();
>
>         for (Entry<String, String[]> entry :
> extractor.getCsv().entrySet()) {
>
>             readedSize++;
>
>             Bulletin bulletin = createBulletin(entry.getValue());
>
>             bulletins.put(bulletin, createPdf(bulletin, entry.getValue()));
>
>             if (bulletins.size()>=SAVE_SIZE) {
>
>                 LOGGER.info("Saved " + SAVE_SIZE + " to the DB");
>
>                 bulletinService.saveBulletins(bulletins);
>
>                 this.report.addReaded(SAVE_SIZE);
>
>                 bulletins = Maps.newHashMap();
>
>             }
>
>         }
>
>         this.report.addReaded(bulletins.size());
>
>         bulletinService.saveBulletins(bulletins);
>
>     }
>
>
>
>     /**
>
>      *
>
>      * @param bulletin bulletin info what needs to be filled in
>
>      * @param data the data what must be injected into the template.
>
>      * @return the created bulletin.
>
>      * @throws Exception => OdfTextDocument.loadDocument throws raw
> exception so can't be more specified here.
>
>      */
>
>     private byte[] createPdf(Bulletin bulletin, String[] data) throws
> Exception {
>
>         InputStream in = null;
>
>         OdfTextDocument document = null;
>
>         ByteArrayOutputStream output = null;
>
>         try {
>
>             if ("NL".equalsIgnoreCase(data[LANGUAGE])) {
>
>                 Objects.requireNonNull(templateNL, "Nederlandstalige
> template is niet aanwezig.");
>
>                 Objects.requireNonNull(extractor.getBulletinTitle(),
> "Nederlandstalige titel is niet aanwezig.");
>
>                 in = new ByteArrayInputStream(templateNL);
>
>                 bulletin.setTitle(extractor.getBulletinTitle());
>
>             } else if ("FR".equalsIgnoreCase(data[LANGUAGE])) {
>
>                 Objects.requireNonNull(templateFR, "Franstalige template
> is niet aanwezig.");
>
>                 Objects.requireNonNull(extractor.getBulletinTitleFR(),
> "Franstalige titel is niet aanwezig.");
>
>                 in = new ByteArrayInputStream(templateFR);
>
>                 bulletin.setTitle(extractor.getBulletinTitleFR());
>
>             } else {
>
>                 throw new IOException("Kan niet vinden of het NL of FR
> moet zijn. Is deze op de 3de entry in de csv?");
>
>             }
>
>             document = OdfTextDocument.loadDocument(in);
>
>
>
>
>
>             //TODO : FIX OutOfMEM issue
>
> //            replace("%name%", data[NAME], document);
>
> //            replace("%firstName%", data[FIRST_NAME], document);
>
> //            replace("%street%", data[STREET], document);
>
> //            replace("%city%", data[ZIP] + " " + data[CITY], document);
>
> //            replace("%birthDate%", data[BIRTH_DATE], document);
>
> //            replace("%formNr%", data[NUMBER], document);
>
> //            replace("%sendDate%", "//TODO : TO BE CONFIRMED", document);
>
> //            replace("%employedBy%", data[EMPLOYD_BY], document);
>
>
>
>             output = new ByteArrayOutputStream();
>
>             document.save(output);
>
>             PdfConverter.getInstance().convert(document, output, options);
>
>
>
>             output.flush();
>
>             return output.toByteArray();
>
>         } finally {
>
>             close(in);
>
>             close(document);
>
>             close(output);
>
>
>
>         }
>
>     }
>
>
>
>
>
> Thx in advance.
>
>
>
> Filip
>
>
>
>
>
> The best way to learn *anything* on the Internet
>
> isn't to post a question but instead to post the wrong answer.
>
> No one wants to help the noob that can't figure it out,
>
> but everyone wants to correct the guy who is wrong.
>
>
>
> Filip Cossaer
> 1SM
> CC V&C
>
> 9-6321-10435
>
> Intranet <http://intranet.mil.intra/sites/Portal/Pages/Default.aspx>
>
>
>
>
>
> This e-mail and any attachments may contain sensitive and
> privileged information. If you are not the intended recipient,
> please notify the sender immediately by return e-mail,
> delete this e-mail and destroy any copies.
> Any dissemination or use of this information by a person other
> than the intended recipient is unauthorized and may be illegal.
>
>

Reply via email to