I am working with Lucene 4.8.0 and I have a DirectoryReader that I can't close. When I try I get the following error :
Caused by: java.lang.RuntimeException: java.io.IOException: The handle is invalid
at apache.lucene.util.IOUtils.reThrowUnchecked(IOUtils.java:368)
at apache.lucene.index.SegmentCoreReaders.notifyCoreClosedListeners(SegmentCoreReaders.java:203)
at apache.lucene.index.SegmentCoreReaders.decRef(SegmentCoreReaders.java:183)
at apache.lucene.index.SegmentReader.doClose(SegmentReader.java:258)
at apache.lucene.index.IndexReader.decRef(IndexReader.java:243)
at apache.lucene.index.StandardDirectoryReader.doClose(StandardDirectoryReader.java:364)
at apache.lucene.index.IndexReader.decRef(IndexReader.java:243)
at apache.lucene.index.IndexReader.close(IndexReader.java:479)
My code is as follows :
FSDirectory indexDir = null;
DirectoryReader dirReader = null
try{
indexDir = new SimpleFSDirectory(new File(baseDir + "/index"),null);
dirReader = DirectoryReader.open(indexDir);
//operations
finally {
if (dirReader != null) {
dirReader.close();
}
if (indexDir != null) {
indexDir.close();
}
}
But this crashes at the dirReader.close(). I am new to Lucene, if I missed something well known or obvious I am sorry.
Related
I am working on file scanner App and clear cache it is crash on activity . my application has clear cache like boost application, unstall apk from app Ram boost etc ........
private void travelPath(File root, int level) {
if (root == null || !root.exists() || level > SCAN_LEVEL) {
return;
}
File[] lists = root.listFiles();
for (File file : lists) {
if (file.isFile()) {
String name = file.getName();
JunkInfo info = null;
if (name.endsWith(".apk")) {
info = new JunkInfo();
info.mSize = file.length();
info.name = name;
info.mPath = file.getAbsolutePath();
info.mIsChild = false;
info.mIsVisible = true;
mApkInfo.mChildren.add(info);
mApkInfo.mSize += info.mSize;
} else if (name.endsWith(".log")) {
info = new JunkInfo();
info.mSize = file.length();
info.name = name;
info.mPath = file.getAbsolutePath();
info.mIsChild = false;
info.mIsVisible = true;
mLogInfo.mChildren.add(info);
mLogInfo.mSize += info.mSize;
} else if (name.endsWith(".tmp") || name.endsWith(".temp")) {
info = new JunkInfo();
info.mSize = file.length();
info.name = name;
info.mPath = file.getAbsolutePath();
info.mIsChild = false;
info.mIsVisible = true;
mTmpInfo.mChildren.add(info);
mTmpInfo.mSize += info.mSize;
}
if (info != null) {
mCallback.onProgress(info);
}
} else {
if (level < SCAN_LEVEL) {
travelPath(file, level + 1);
}
}
}
}
and LogCat error is :
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:353)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at com.example.dell.testnew.custom.OverallScanTask.travelPath(OverallScanTask.java:35)
at com.example.dell.testnew.custom.OverallScanTask.doInBackground(OverallScanTask.java:85)
at com.example.dell.testnew.custom.OverallScanTask.doInBackground(OverallScanTask.java:15)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at com.example.dell.testnew.custom.OverallScanTask.travelPath(OverallScanTask.java:35)
at com.example.dell.testnew.custom.OverallScanTask.doInBackground(OverallScanTask.java:85)
at com.example.dell.testnew.custom.OverallScanTask.doInBackground(OverallScanTask.java:15)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
getting error here for loop for a file scanner
Thank you in Advance for help i will appreciate your answer
Files.listFiles can return null if it is not a directory:
Returns an array of abstract pathnames denoting the files and directories in
the directory denoted by this abstract pathname. The array will be
empty if the directory is empty. Returns null if this abstract
pathname does not denote a directory, or if an I/O error occurs.
If you do not expect it to be null, then you should probably revisit your code logic and find a workaround, otherwise you can easily handle it with a null check.
I am trying to download video from RTSP stream to a file on my computer using the Xuggler 5.4 library.
String outputFilename = "D:\\downloadedrtsp.avi";
String inputSource = "rtsp://[ip-address]:[port]/user=[username]&[password]=password&channel=1&stream=1.sdp";
try {
IContainer container = IContainer.make();
IMetaData im = IMetaData.make();
im.setValue("max_delay", (1000000l) + "");
int retval = im.setValue("rtsp_transport", "tcp");
container.open(inputSource, IContainer.Type.READ, null, false, true, im, null);
IMediaReader mediaReader = ToolFactory.makeReader(container);
IMediaWriter mediaWriter = ToolFactory.makeWriter(outputFilename, mediaReader);
mediaReader.addListener(mediaWriter);
IError error;
while ((error = mediaReader.readPacket()) == null) {
logger.info("reading packet");
}
} catch (Exception e) {
e.printStackTrace();
}
But the code fails with a stacktrace
15:40:52.500 [main] ERROR org.ffmpeg - [tcp # 00000000171C6BE0] Failed to resolve hostname \downloadedrtsp.avi: ???? ???? ??????????.
15:40:52.500 [main] ERROR com.xuggle.xuggler - Error: could not write header for container (../../../../../../../csrc/com/xuggle/xuggler/Container.cpp:827)
java.lang.RuntimeException: Error Operation not permitted, failed to write header to container com.xuggle.xuggler.IContainer#387681280[url:D:\downloadedrtsp.avi;type:WRITE;format:com.xuggle.xuggler.IContainerFormat#387719536[oname:rtsp;olongname:RTSP output format;omimetype:null;oextensions:null;];] while establishing stream com.xuggle.xuggler.IStream#387690704[index:1;id:0;streamcoder:com.xuggle.xuggler.IStreamCoder#384527536[codec=com.xuggle.xuggler.ICodec#387719392[type=CODEC_TYPE_AUDIO;id=CODEC_ID_AAC;name=libvo_aacenc;];time base=1/8000;frame rate=0/0;sample rate=8000;channels=1;];framerate:0/0;timebase:1/90000;direction:OUTBOUND;]
at com.xuggle.mediatool.MediaWriter.getStream(MediaWriter.java:1058)
at com.xuggle.mediatool.MediaWriter.encodeAudio(MediaWriter.java:830)
at com.xuggle.mediatool.MediaWriter.onAudioSamples(MediaWriter.java:1441)
at com.xuggle.mediatool.AMediaToolMixin.onAudioSamples(AMediaToolMixin.java:89)
at com.xuggle.mediatool.MediaReader.dispatchAudioSamples(MediaReader.java:628)
at com.xuggle.mediatool.MediaReader.decodeAudio(MediaReader.java:555)
at com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:469)
at ua.datalink.main.StreamTranscodingExample.readHigherLevel(StreamTranscodingExample.java:103)
at ua.datalink.main.StreamTranscodingExample.main(StreamTranscodingExample.java:121)
The file is created on program startup, but it's empty. Where can the problem lies? I have spend hours to figure it out, but still no result.
I had a piece of code to read ofx file to retrieve several tags (such as acct number, balance etc.) I am using net.sf.ofx4j
Piece of code:
public void parse(String filename) throws OFXParseException, IOException, SQLException {
AggregateUnmarshaller<ResponseEnvelope> unmarshaller = new AggregateUnmarshaller<ResponseEnvelope>(
ResponseEnvelope.class);
FileInputStream file = null;
try {
file = new FileInputStream(filename);
ResponseEnvelope envelope = unmarshaller.unmarshal(file);
BankingResponseMessageSet messageSet = (BankingResponseMessageSet) envelope.getMessageSet(MessageSetType.banking);
List<BankStatementResponseTransaction> responses = messageSet.getStatementResponses();
for (BankStatementResponseTransaction response : responses) {
BankStatementResponse message = response.getMessage();
String currencyCode = message.getCurrencyCode();
String acct_number = message.getAccount().getAccountNumber();
double av = message.getAvailableBalance().getAmount();
double cur = message.getLedgerBalance().getAmount();
AccountType acct_type = message.getAccount().getAccountType();
}
} catch (OFXParseException e) {
System.out.println("Error: " + e.getMessage());
}
return null;
}
It was working fine until one day it started throwing the following exception:
net.sf.ofx4j.io.AggregateStackContentHandler onElement
INFO: Element INTU.BID is not supported on aggregate SONRS (class net.sf.ofx4j.domain.data.signon.SignonResponse) at index 70.
net.sf.ofx4j.io.AggregateStackContentHandler onElement
INFO: Element INTU.USERID is not supported on aggregate SONRS (class net.sf.ofx4j.domain.data.signon.SignonResponse) at index 70.
Exception in thread "main" java.lang.IllegalStateException: java.io.IOException: Unexpected EOF
Thanks
Hope ofx file format should be changed. because you are requesting (MessageSetType.*banking*). But in your ofx file may be have credit card details.
In early, transaction data is include in .ofx file inside the <BANKMSGSRSV1> tag.
But now transaction data is include in <CREDITCARDMSGSRSV> tag. you need to change the data receiving code.
Hope you can get some help from this. Thank you
I am crawling a webpage and after crawling it extract all the links from that webpage and then I am trying to parse all the url using Apache Tika and BoilerPipe by using below code so for some url it is parsing very well but for some I get error like this. And it shows some error on HTMLParser.java: line number 102. This is line number 102 in HTMLParser.java
String parsedText = tika.parseToString(htmlStream, md);
I have provided the HTMLParse code also.
org.apache.tika.exception.TikaException: TIKA-198: Illegal IOException from org.apache.tika.parser.microsoft.ooxml.OOXMLParser#67c28a6a
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:203)
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:197)
at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:135)
at org.apache.tika.Tika.parseToString(Tika.java:357)
at edu.uci.ics.crawler4j.crawler.HTMLParser.parse(HTMLParser.java:102)
at edu.uci.ics.crawler4j.crawler.WebCrawler.handleHtml(WebCrawler.java:227)
at edu.uci.ics.crawler4j.crawler.WebCrawler.processPage(WebCrawler.java:299)
at edu.uci.ics.crawler4j.crawler.WebCrawler.run(WebCrawler.java:118)
at java.lang.Thread.run(Unknown Source)
Caused by: java.util.zip.ZipException: invalid block type
at java.util.zip.InflaterInputStream.read(Unknown Source)
at java.util.zip.ZipInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource$FakeZipEntry.<init>(ZipInputStreamZipEntrySource.java:114)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.<init>(ZipInputStreamZipEntrySource.java:55)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:82)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:220)
at org.apache.poi.extractor.ExtractorFactory.createExtractor(ExtractorFactory.java:152)
at org.apache.tika.parser.microsoft.ooxml.OOXMLExtractorFactory.parse(OOXMLExtractorFactory.java:65)
at org.apache.tika.parser.microsoft.ooxml.OOXMLParser.parse(OOXMLParser.java:67)
at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:197)
... 8 more
This is my HTMLParser.java file-
public void parse(String htmlContent, String contextURL) {
InputStream htmlStream = null;
text = null;
title = null;
metaData = new HashMap<String, String>();
urls = new HashSet<String>();
char[] chars = htmlContent.toCharArray();
bulletParser.setCallback(textExtractor);
bulletParser.parse(chars);
try {
text = articleExtractor.getText(htmlContent);
} catch (BoilerpipeProcessingException e) {
e.printStackTrace();
}
if (text == null){
text = textExtractor.text.toString().trim();
}
title = textExtractor.title.toString().trim();
try {
Metadata md = new Metadata();
String utfHtmlContent = new String(htmlContent.getBytes(),"UTF-8");
htmlStream = new ByteArrayInputStream(utfHtmlContent.getBytes());
//The below line is at the line number 102 according to error above
String parsedText = tika.parseToString(htmlStream, md);
//very unlikely to happen
if (text == null){
text = parsedText.trim();
}
processMetaData(md);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(htmlStream);
}
bulletParser.setCallback(linkExtractor);
bulletParser.parse(chars);
Iterator<String> it = linkExtractor.urls.iterator();
String baseURL = linkExtractor.base();
if (baseURL != null) {
contextURL = baseURL;
}
int urlCount = 0;
while
(it.hasNext()) {
String href = it.next();
href = href.trim();
if (href.length() == 0) {
continue;
}
String hrefWithoutProtocol = href.toLowerCase();
if (href.startsWith("http://")) {
hrefWithoutProtocol = href.substring(7);
}
if (hrefWithoutProtocol.indexOf("javascript:") < 0
&& hrefWithoutProtocol.indexOf("#") < 0) {
URL url = URLCanonicalizer.getCanonicalURL(href, contextURL);
if (url != null) {
urls.add(url.toExternalForm());
urlCount++;
if (urlCount > MAX_OUT_LINKS) {
break;
}
}
}
}
}
Any suggestions will be appreciated.
Sounds like a malformed OOXML document (.docx, .xlsx, etc.). To check whether the problem still occurs with the latest Tika version, you can download the tika-app jar and run it like this:
java -jar tika-app-1.0.jar --text http://url.of.the/troublesome/document.docx
This should print out the text contained in the document. If it doesn't work, please file a bug report with the URL of the troublesome document (or attach the document if it's not publicly available).
I had same issue, I found that documents(docx) files which I was trying to parse was not actually simple document, It was form developed in microsoft word with text and input fields beside label text.
I removed such files from folder and post rest of all files to Solr engine for parsing and indexing, It worked.
i have this runtime error in my logcat:
05-11 06:24:23.672: ERROR/AndroidRuntime(327): java.lang.RuntimeException:
Unable to create application net.osmand.activities.OsmandApplication:
java.lang.IllegalArgumentException: InputStream cannot be null
...
after debugin i found the exception comme how???
in this methode :
private BaseOsmandRender loadRenderer(String name, Set<String> loadedRenderers) throws IOException, SAXException {
InputStream is = null;
if(externalRenderers.containsKey(name)){
is = new FileInputStream(externalRenderers.get(name));
} else if(internalRenderers.containsKey(name)){
is = OsmandRenderingRulesParser.class.getResourceAsStream(internalRenderers.get(name));
} else {
throw new IllegalArgumentException("Not found " + name); //$NON-NLS-1$
}
BaseOsmandRender b = new BaseOsmandRender();
b.init(is);
loadedRenderers.add(name);
List<BaseOsmandRender> dependencies = new ArrayList<BaseOsmandRender>();
for (String s : b.getDepends()) {
if (loadedRenderers.contains(s)) {
the "is" varible is always null
any help please
If I remember correctly, getResourceAsStream returns null if it cannot find the resource. I suspect that's the cause of your problem.
There are some crazy restrictions for files in application resources.
If you trying to load resources, try to make *.mp3 extension for them. Its magic.