Hi,

It's usual behavior for any function that consumes stream (it's not Tika
related).
In this case you can wrap it with BufferedInputStream, since detection
needs only beginng of the file.

Code snippet is:

InputStream bis = new BufferedInputStream(inputsbust);
tika.detect(bis);

Tika resets stream after use, so buffered input stream can be used again.

-- 
Best regards,
Konstantin Gribov

Thu Jan 29 2015 at 18:16:32, Gabriele Guidi <gabriele.gu...@eng.it>:

Thanks for your answer.
> I had the same behaviour with tika 1.6 and 1.5.
> I found a workaround, the problem seems to happen with only InputStream, so
> now I use byte[] and it's OK.
>
> Thanks again
> Il 29/gen/2015 07:24 "Mattmann, Chris A (3980)" <
> chris.a.mattm...@jpl.nasa.gov> ha scritto:
>
> > Dear Gabriele,
> >
> > Thanks for your question. It should be sent to dev@tika.apache.org
> > (moving dev-ow...@tika.apache.org to BCC).
> >
> > I’ll take a look tomorrow if someone else hasn’t answered yet.
> >
> > Cheers,
> > Chris
> >
> >
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > Chris Mattmann, Ph.D.
> > Chief Architect
> > Instrument Software and Science Data Systems Section (398)
> > NASA Jet Propulsion Laboratory Pasadena, CA 91109 USA
> > Office: 168-519, Mailstop: 168-527
> > Email: chris.a.mattm...@nasa.gov
> > WWW:  http://sunset.usc.edu/~mattmann/
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > Adjunct Associate Professor, Computer Science Department
> > University of Southern California, Los Angeles, CA 90089 USA
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >
> >
> >
> >
> >
> >
> > -----Original Message-----
> > From: Gabriele Guidi <gabriele.gu...@eng.it>
> > Date: Wednesday, January 28, 2015 at 5:25 AM
> > To: "dev-ow...@tika.apache.org" <dev-ow...@tika.apache.org>
> > Subject: multiple detect call -> different results (tika 1.7)
> >
> > >
> > >
> > >Hi,
> > >
> > >
> > >I found a strange behavior. I have p7m file, then I extract file inside
> > >the signed one, after that I use tika to discover mime type, the first
> > >call it gives me "application/pdf" (that's correct). BUT every next call
> > >to the detect method of Tika to the
> > > same inputStream gives me "application/octet-stream". ...why?
> > >I cannot understand the behavior ...and find a solution.
> > >
> > >
> > >Just a snipped of code:
> > >
> > >
> > >
> > >InputStream inputsbust = content.getContentStream();
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >System.out.println(" 1 mime " + filepath + " : "
> > >+ tika.detect(inputsbust));
> > >System.out.println(" 2 mime " + filepath + " : "
> > >+ tika.detect(inputsbust));
> > >System.out.println(" 3 mime " + filepath + " : "
> > >+ tika.detect(inputsbust));
> > >
> > >
> > >
> > >Result:
> > >
> > > 1 mime /home/gguidi/01_file.pdf : application/pdf
> > > 2 mime /home/gguidi/01_file.pdf : application/octet-stream
> > > 3 mime /home/gguidi/01_file.pdf : application/octet-stream
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >Thanks
> > >
> > >
> > >--
> > >
> > >
> > >Gabriele Guidi
> > >Direzione Pubblica Amministrazione
> > >gabriele.gu...@eng.it
> > >
> > >Engineering Ingegneria Informatica spa
> > >Via Marconi, 10 - 40122, Bologna
> > >Tel. +39-051.0435135
> > >www.eng.it <http://www.eng.it>
> > >
> > >
> > >Rispetta l'ambiente. Non stampare questa e-mail se non necessario.
> > >Respect the environment. Please don't print this e-mail unless you
> really
> > >need to.
> > >Le informazioni trasmesse sono destinate esclusivamente alla persona o
> > >alla società in indirizzo e sono da intendersi confidenziali e
> riservate.
> > >Ogni trasmissione, inoltro, diffusione o altro uso
> > > di queste informazioni a persone o società differenti dal destinatario
> è
> > >proibita. Se ricevete questa comunicazione per errore, contattate il
> > >mittente e cancellate le informazioni da ogni computer.
> > >The information transmitted is intended only for the person or entity to
> > >which it is addressed and may contain confidential and/or privileged
> > >material. Any review, retransmission, dissemination or other use of, or
> > >taking of any action in reliance upon, this
> > > information by persons or entities other than the intended recipient is
> > >prohibited. If you received this in error, please contact the sender and
> > >delete the material from any computer.
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
>

Reply via email to