Java Code Examples for org.apache.solr.common.util.ContentStreamBase#FileStream
The following examples show how to use
org.apache.solr.common.util.ContentStreamBase#FileStream .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCSVLoader.java From lucene-solr with Apache License 2.0 | 5 votes |
void loadLocal(String... args) throws Exception { LocalSolrQueryRequest req = (LocalSolrQueryRequest)req(args); // TODO: stop using locally defined streams once stream.file and // stream.body work everywhere List<ContentStream> cs = new ArrayList<>(1); ContentStreamBase f = new ContentStreamBase.FileStream(new File(filename)); f.setContentType("text/csv"); cs.add(f); req.setContentStreams(cs); h.query("/update",req); }
Example 2
Source File: ShowFileRequestHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) { File adminFile = getAdminFileFromFileSystem(req, rsp, hiddenFiles); if (adminFile == null) { // exception already recorded return; } // Make sure the file exists, is readable and is not a hidden file if( !adminFile.exists() ) { log.error("Can not find: {} [{}]", adminFile.getName(), adminFile.getAbsolutePath()); rsp.setException(new SolrException ( ErrorCode.NOT_FOUND, "Can not find: "+adminFile.getName() + " ["+adminFile.getAbsolutePath()+"]" )); return; } if( !adminFile.canRead() || adminFile.isHidden() ) { log.error("Can not show: {} [{}]", adminFile.getName(), adminFile.getAbsolutePath()); rsp.setException(new SolrException ( ErrorCode.NOT_FOUND, "Can not show: "+adminFile.getName() + " ["+adminFile.getAbsolutePath()+"]" )); return; } // Show a directory listing if( adminFile.isDirectory() ) { // it's really a directory, just go for it. int basePath = adminFile.getAbsolutePath().length() + 1; NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>(); for( File f : adminFile.listFiles() ) { String path = f.getAbsolutePath().substring( basePath ); path = path.replace( '\\', '/' ); // normalize slashes if (isHiddenFile(req, rsp, f.getName().replace('\\', '/'), false, hiddenFiles)) { continue; } SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>(); files.add( path, fileInfo ); if( f.isDirectory() ) { fileInfo.add( "directory", true ); } else { // TODO? content type fileInfo.add( "size", f.length() ); } fileInfo.add( "modified", new Date( f.lastModified() ) ); } rsp.add("files", files); } else { // Include the file contents //The file logic depends on RawResponseWriter, so force its use. ModifiableSolrParams params = new ModifiableSolrParams( req.getParams() ); params.set( CommonParams.WT, "raw" ); req.setParams(params); ContentStreamBase content = new ContentStreamBase.FileStream( adminFile ); content.setContentType(req.getParams().get(USE_CONTENT_TYPE)); rsp.add(RawResponseWriter.CONTENT, content); } rsp.setHttpCaching(false); }
Example 3
Source File: ContentStreamUpdateRequest.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Add a File to the {@link org.apache.solr.common.util.ContentStream}s. * @param file The File to add. * @throws IOException if there was an error with the file. * * @see #getContentStreams() * @see org.apache.solr.common.util.ContentStreamBase.FileStream */ public void addFile(File file, String contentType) throws IOException { ContentStreamBase cs = new ContentStreamBase.FileStream(file); cs.setContentType(contentType); addContentStream(cs); }