MCPcopy Create free account
hub / github.com/apache/solr / postFile

Method postFile

solr/core/src/java/org/apache/solr/cli/PostTool.java:822–895  ·  view source on GitHub ↗

Opens the file and posts its contents to the solrUrl, writes to response to output.

(Path file, OutputStream output, String type)

Source from the content-addressed store, hash-verified

820
821 /** Opens the file and posts its contents to the solrUrl, writes to response to output. */
822 public void postFile(Path file, OutputStream output, String type)
823 throws MalformedURLException, URISyntaxException {
824 InputStream is = null;
825
826 URI uri = solrUpdateUrl;
827 String suffix = "";
828 if (auto) {
829 if (type == null) {
830 type = guessType(file);
831 }
832 // TODO: Add a flag that disables /update and sends all to /update/extract, to avoid CSV,
833 // JSON, and XML files
834 // TODO: from being interpreted as Solr documents internally
835 if (type.equals("application/json") && !PostTool.FORMAT_SOLR.equals(format)) {
836 suffix = "/json/docs";
837 String urlStr = appendUrlPath(solrUpdateUrl, suffix).toString();
838 uri = new URI(urlStr);
839 } else if (type.equals("application/xml")
840 || type.equals("text/csv")
841 || type.equals("application/json")) {
842 // Default handler
843 } else {
844 // SolrCell
845 suffix = "/extract";
846 String urlStr = appendUrlPath(solrUpdateUrl, suffix).toString();
847 if (!urlStr.contains("resource.name")) {
848 urlStr =
849 appendParam(
850 urlStr,
851 "resource.name=" + URLEncoder.encode(file.toAbsolutePath().toString(), UTF_8));
852 }
853 if (!urlStr.contains("literal.id")) {
854 urlStr =
855 appendParam(
856 urlStr,
857 "literal.id=" + URLEncoder.encode(file.toAbsolutePath().toString(), UTF_8));
858 }
859 uri = new URI(urlStr);
860 }
861 } else {
862 if (type == null) {
863 type = DEFAULT_CONTENT_TYPE;
864 }
865 }
866 if (dryRun) {
867 info(
868 "DRY RUN of POSTing file "
869 + file.getFileName()
870 + (auto ? " (" + type + ")" : "")
871 + " to [base]"
872 + suffix);
873 } else {
874 try {
875 info(
876 "POSTing file "
877 + file.getFileName()
878 + (auto ? " (" + type + ")" : "")
879 + " to [base]"

Callers 1

postFilesMethod · 0.95

Calls 13

guessTypeMethod · 0.95
appendUrlPathMethod · 0.95
appendParamMethod · 0.95
infoMethod · 0.95
postDataMethod · 0.95
warnMethod · 0.95
encodeMethod · 0.80
getFileNameMethod · 0.80
toStringMethod · 0.65
sizeMethod · 0.65
closeMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected