Source:
public void getAllDocids(Compression compression) throws IOException { Query q = new FieldValueQuery(LuceneDocumentGenerator.FIELD_ID); IndexSearcher searcher = new IndexSearcher(reader); ScoreDoc[] scoreDocs; try { scoreDocs = searcher.search(new FieldValueQuery(LuceneDocumentGenerator.FIELD_ID), reader.maxDoc(), BREAK_SCORE_TIES_BY_DOCID).scoreDocs; } catch (IllegalStateException e) { scoreDocs = searcher.search(new FieldValueQuery(TweetGenerator.StatusField.ID_LONG.name), reader.maxDoc(), BREAK_SCORE_TIES_BY_TWEETID).scoreDocs; } String basePath = directory.getDirectory().getFileName().toString() + ".allDocids"; OutputStream outStream = null; String outputPath = ""; switch (compression) { case RAW: outputPath = basePath+".txt"; outStream = Files.newOutputStream(Paths.get(outputPath)); break; case GZ: outputPath = basePath+".gz"; outStream = new GzipCompressorOutputStream(new BufferedOutputStream( Files.newOutputStream(Paths.get(outputPath)))); break; case ZIP: outputPath = basePath+".zip"; outStream = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(Paths.get(outputPath)))); ((ZipOutputStream) outStream).putNextEntry(new ZipEntry(basePath)); break; case BZ2: outputPath = basePath+".bz2"; outStream = new BZip2CompressorOutputStream(new BufferedOutputStream( Files.newOutputStream(Paths.get(outputPath)))); break; } for (int i = 0; i < scoreDocs.length; i++) { StringBuilder builder = new StringBuilder(); builder.append(searcher.doc(scoreDocs[i].doc).getField(LuceneDocumentGenerator.FIELD_ID).stringValue()).append("\n"); outStream.write(builder.toString().getBytes(StandardCharsets.UTF_8)); } outStream.close(); System.out.println(String.format("All Documents IDs are output to: %s", outputPath)); }

Target:
public void getAllDocids(Compression compression) throws IOException { Query q = new FieldValueQuery(LuceneDocumentGenerator.FIELD_ID); IndexSearcher searcher = new IndexSearcher(reader); ScoreDoc[] scoreDocs; try { scoreDocs = searcher.search(new FieldValueQuery(LuceneDocumentGenerator.FIELD_ID), reader.maxDoc(), BREAK_SCORE_TIES_BY_DOCID).scoreDocs; } catch (IllegalStateException e) { scoreDocs = searcher.search(new FieldValueQuery(TweetGenerator.StatusField.ID_LONG.name), reader.maxDoc(), BREAK_SCORE_TIES_BY_TWEETID).scoreDocs; } String basePath = directory.getDirectory().getFileName().toString() + ".allDocids"; OutputStream outStream = null; String outputPath = ""; switch (compression) { case NONE: outputPath = basePath+".txt"; outStream = Files.newOutputStream(Paths.get(outputPath)); break; case GZ: outputPath = basePath+".gz"; outStream = new GzipCompressorOutputStream(new BufferedOutputStream(Files.newOutputStream(Paths.get(outputPath)))); break; case ZIP: outputPath = basePath+".zip"; outStream = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(Paths.get(outputPath)))); ((ZipOutputStream) outStream).putNextEntry(new ZipEntry(basePath)); break; case BZ2: outputPath = basePath+".bz2"; outStream = new BZip2CompressorOutputStream(new BufferedOutputStream(Files.newOutputStream(Paths.get(outputPath)))); break; } for (int i = 0; i < scoreDocs.length; i++) { StringBuilder builder = new StringBuilder(); builder.append(searcher.doc(scoreDocs[i].doc).getField(LuceneDocumentGenerator.FIELD_ID).stringValue()).append("\n"); outStream.write(builder.toString().getBytes(StandardCharsets.UTF_8)); } outStream.close(); System.out.println(String.format("All Documents IDs are output to: %s", outputPath)); }