code maintenance - removed warnings and replaced deprecated functions

pull/666/head
Michael Peter Christen 4 months ago
parent feca150672
commit 6ef3a0fca5

2
.gitignore vendored

@ -9,6 +9,8 @@ classes/
RELEASE/ RELEASE/
/yacy.pid /yacy.pid
.DS_Store .DS_Store
/yacy/source/.DS_Store
/htroot/.DS_Store
/DATA.bkp /DATA.bkp
/DATA.1 /DATA.1
/gen /gen

@ -29,7 +29,6 @@ import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.StringTokenizer; import java.util.StringTokenizer;
public class ISO8601Formatter extends AbstractFormatter implements DateFormatter { public class ISO8601Formatter extends AbstractFormatter implements DateFormatter {

@ -36,6 +36,7 @@ import java.io.Serializable;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -2368,7 +2369,11 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
*/ */
public java.net.URL getURL() throws MalformedURLException { public java.net.URL getURL() throws MalformedURLException {
if (!(isHTTP() || isHTTPS() || isFTP())) throw new MalformedURLException(); if (!(isHTTP() || isHTTPS() || isFTP())) throw new MalformedURLException();
return new java.net.URL(this.toNormalform(false)); try {
return new java.net.URI(this.toNormalform(false)).toURL();
} catch (URISyntaxException e) {
throw new MalformedURLException(e.getMessage());
}
} }
/** /**
@ -2655,6 +2660,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
return splitpattern.split(normalizedURL.toLowerCase()); // word components of the url return splitpattern.split(normalizedURL.toLowerCase()); // word components of the url
} }
@SuppressWarnings("deprecation")
public static void main(final String[] args) { public static void main(final String[] args) {
final String[][] test = new String[][]{ final String[][] test = new String[][]{
new String[]{null, "file://y:/"}, new String[]{null, "file://y:/"},
@ -2722,7 +2728,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
url = element[1]; url = element[1];
try {aURL = MultiProtocolURL.newURL(environment, url);} catch (final MalformedURLException e) {e.printStackTrace(); aURL = null;} try {aURL = MultiProtocolURL.newURL(environment, url);} catch (final MalformedURLException e) {e.printStackTrace(); aURL = null;}
if (environment == null) { if (environment == null) {
try {jURL = new java.net.URL(url);} catch (final MalformedURLException e) {jURL = null;} try {jURL = new java.net.URI(url).toURL();} catch (final MalformedURLException | URISyntaxException e) {jURL = null;}
} else { } else {
try {jURL = new java.net.URL(new java.net.URL(environment), url);} catch (final MalformedURLException e) {jURL = null;} try {jURL = new java.net.URL(new java.net.URL(environment), url);} catch (final MalformedURLException e) {jURL = null;}
} }

@ -22,6 +22,8 @@ package net.yacy.cora.federate;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -366,8 +368,8 @@ public class FederateSearchManager {
final String hrefurltxt = sdoc.getFieldValue(WebgraphSchema.target_protocol_s.getSolrFieldName()) + "://" + sdoc.getFieldValue(WebgraphSchema.target_urlstub_s.getSolrFieldName()); final String hrefurltxt = sdoc.getFieldValue(WebgraphSchema.target_protocol_s.getSolrFieldName()) + "://" + sdoc.getFieldValue(WebgraphSchema.target_urlstub_s.getSolrFieldName());
URL url; URL url;
try { try {
url = new URL(hrefurltxt); url = new URI(hrefurltxt).toURL();
} catch (final MalformedURLException ex) { } catch (final MalformedURLException | URISyntaxException ex) {
LOG.warn("OpenSearch description URL is malformed : " + hrefurltxt); LOG.warn("OpenSearch description URL is malformed : " + hrefurltxt);
continue; continue;
} }

@ -21,6 +21,8 @@
package net.yacy.cora.federate.solr.connector; package net.yacy.cora.federate.solr.connector;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -82,8 +84,8 @@ public class ShardSelection implements Iterable<SolrClient> {
if (sif != null) { if (sif != null) {
final String url = (String) sif.getValue(); final String url = (String) sif.getValue();
if (url != null && url.length() > 0) try { if (url != null && url.length() > 0) try {
return server4write(new URL(url)); return server4write(new URI(url).toURL());
} catch (final IOException e) { } catch (final IOException | URISyntaxException e) {
ConcurrentLog.logException(e); ConcurrentLog.logException(e);
return this.server.get(0); return this.server.get(0);
} }
@ -97,7 +99,11 @@ public class ShardSelection implements Iterable<SolrClient> {
public SolrClient server4write(final String host) throws IOException { public SolrClient server4write(final String host) throws IOException {
if (host == null) throw new IOException("sharding - host url, host empty: " + host); if (host == null) throw new IOException("sharding - host url, host empty: " + host);
if (host.indexOf("://") >= 0) return server4write(new URL(host)); // security catch for accidantly using the wrong method if (host.indexOf("://") >= 0) try {
return server4write(new URI(host).toURL()); // security catch for accidently using the wrong method
} catch (URISyntaxException e) {
throw new IOException("sharding - host url, host invalid: " + host);
}
if (this.method == Method.MODULO_HOST_MD5) { if (this.method == Method.MODULO_HOST_MD5) {
try { try {
final MessageDigest digest = MessageDigest.getInstance("MD5"); final MessageDigest digest = MessageDigest.getInstance("MD5");

@ -66,7 +66,6 @@ import org.apache.solr.servlet.SolrRequestParsers;
* *
* @since solr 1.3 * @since solr 1.3
*/ */
@SuppressWarnings("deprecation")
public class EmbeddedSolrServer extends SolrClient { public class EmbeddedSolrServer extends SolrClient {
private static final long serialVersionUID = -6657217211811383651L; private static final long serialVersionUID = -6657217211811383651L;

@ -27,6 +27,8 @@ package net.yacy.cora.plugin;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
@ -46,11 +48,11 @@ public class ClassProvider {
if (!path.startsWith("/")) path = "/" + path; if (!path.startsWith("/")) path = "/" + path;
URL[] urls; URL[] urls;
try { try {
urls = new URL[]{new URL("file", "", path)}; urls = new URL[]{new URI("file", "", path).toURL()};
final URLClassLoader cl = new URLClassLoader(urls); final URLClassLoader cl = new URLClassLoader(urls);
c = cl.loadClass(classname); c = cl.loadClass(classname);
cl.close(); cl.close();
} catch (ClassNotFoundException | IOException e) { } catch (ClassNotFoundException | IOException | URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

@ -729,7 +729,7 @@ public class RequestHeader extends HeaderFramework implements HttpServletRequest
return _request.getLocale(); return _request.getLocale();
} else if (super.containsKey(HeaderFramework.ACCEPT_LANGUAGE)) { } else if (super.containsKey(HeaderFramework.ACCEPT_LANGUAGE)) {
final String lng = super.get(HeaderFramework.ACCEPT_LANGUAGE); final String lng = super.get(HeaderFramework.ACCEPT_LANGUAGE);
return new Locale(lng); return Locale.forLanguageTag(lng);
} }
return Locale.getDefault(); // to avoid dependency on Switchboard just use system default return Locale.getDefault(); // to avoid dependency on Switchboard just use system default
} }

@ -119,7 +119,7 @@ public class FTPClient {
private final Map<String, entryInfo> infoCache = new HashMap<String, entryInfo>(); private final Map<String, entryInfo> infoCache = new HashMap<String, entryInfo>();
// date-format in LIST (english month names) // date-format in LIST (english month names)
private static final SimpleDateFormat lsDateFormat = new SimpleDateFormat("MMM d y H:m", new Locale("en")); private static final SimpleDateFormat lsDateFormat = new SimpleDateFormat("MMM d y H:m", Locale.forLanguageTag("en"));
// TODO: implement RFC 2640 Internationalization // TODO: implement RFC 2640 Internationalization

@ -56,7 +56,6 @@ public class XMLBlacklistImporter extends DefaultHandler {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public synchronized ListAccumulator parse(InputSource input) throws IOException, SAXException { public synchronized ListAccumulator parse(InputSource input) throws IOException, SAXException {
@SuppressWarnings("deprecation")
final XMLReader reader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); final XMLReader reader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
reader.setContentHandler(this); reader.setContentHandler(this);
reader.parse(input); reader.parse(input);

@ -330,7 +330,7 @@ public final class TextParser {
for(final Parser parser : idioms) { for(final Parser parser : idioms) {
/* Wrap in a CloseShieldInputStream to prevent SAX parsers closing the sourceStream /* Wrap in a CloseShieldInputStream to prevent SAX parsers closing the sourceStream
* and so let us eventually reuse the same opened stream with other parsers on parser failure */ * and so let us eventually reuse the same opened stream with other parsers on parser failure */
CloseShieldInputStream nonCloseInputStream = new CloseShieldInputStream(markableStream); CloseShieldInputStream nonCloseInputStream = CloseShieldInputStream.wrap(markableStream);
try { try {
return parseSource(location, mimeType, parser, charset, defaultValency, valencySwitchTagNames, scraper, timezoneOffset, return parseSource(location, mimeType, parser, charset, defaultValency, valencySwitchTagNames, scraper, timezoneOffset,
@ -351,7 +351,7 @@ public final class TextParser {
* (see RFC 7231 section 3.1.2.2 for "Content-Encoding" header specification https://tools.ietf.org/html/rfc7231#section-3.1.2.2)*/ * (see RFC 7231 section 3.1.2.2 for "Content-Encoding" header specification https://tools.ietf.org/html/rfc7231#section-3.1.2.2)*/
final gzipParser gzParser = (gzipParser)parser; final gzipParser gzParser = (gzipParser)parser;
nonCloseInputStream = new CloseShieldInputStream(markableStream); nonCloseInputStream = CloseShieldInputStream.wrap(markableStream);
final Document maindoc = gzipParser.createMainDocument(location, mimeType, charset, gzParser); final Document maindoc = gzipParser.createMainDocument(location, mimeType, charset, gzParser);

@ -112,7 +112,8 @@ public class GenericXMLParser extends AbstractParser implements Parser {
/* Use commons-io XmlStreamReader advanced rules to help with charset detection when source contains no BOM or XML declaration /* Use commons-io XmlStreamReader advanced rules to help with charset detection when source contains no BOM or XML declaration
* (detection algorithm notably also include ContentType transmitted by HTTP headers, here eventually present as mimeType and charset parameters), */ * (detection algorithm notably also include ContentType transmitted by HTTP headers, here eventually present as mimeType and charset parameters), */
final XmlStreamReader reader = new XmlStreamReader(source, mimeType, true, charset); final XmlStreamReader reader = XmlStreamReader.builder().setInputStream(source).setHttpContentType(mimeType).setLenient(true).setCharset(charset).get();
//final XmlStreamReader reader = new XmlStreamReader(source, mimeType, true, charset);
final InputSource saxSource = new InputSource(reader); final InputSource saxSource = new InputSource(reader);
final String detectedCharset = reader.getEncoding(); final String detectedCharset = reader.getEncoding();
@ -176,7 +177,8 @@ public class GenericXMLParser extends AbstractParser implements Parser {
/* Use commons-io XmlStreamReader advanced rules to help with charset detection when source contains no BOM or XML declaration /* Use commons-io XmlStreamReader advanced rules to help with charset detection when source contains no BOM or XML declaration
* (detection algorithm notably also include ContentType transmitted by HTTP headers, here eventually present as mimeType and charset parameters), */ * (detection algorithm notably also include ContentType transmitted by HTTP headers, here eventually present as mimeType and charset parameters), */
final XmlStreamReader reader = new XmlStreamReader(limitedSource, mimeType, true, charsetName); final XmlStreamReader reader = XmlStreamReader.builder().setInputStream(limitedSource).setHttpContentType(mimeType).setLenient(true).setCharset(charsetName).get();
//final XmlStreamReader reader = new XmlStreamReader(limitedSource, mimeType, true, charsetName);
final InputSource saxSource = new InputSource(reader); final InputSource saxSource = new InputSource(reader);
final String detectedCharset = reader.getEncoding(); final String detectedCharset = reader.getEncoding();

@ -60,7 +60,7 @@ public class XZParser extends AbstractCompressorParser {
@Override @Override
protected String getUncompressedFilename(final String filename) { protected String getUncompressedFilename(final String filename) {
return XZUtils.getUncompressedFilename(filename); return XZUtils.getUncompressedFileName(filename);
} }
} }

@ -125,7 +125,7 @@ public class bzipParser extends AbstractParser implements Parser {
// create maindoc for this bzip container, register with supplied url & mime // create maindoc for this bzip container, register with supplied url & mime
maindoc = createMainDocument(location, mimeType, charset, this); maindoc = createMainDocument(location, mimeType, charset, this);
// creating a new parser class to parse the unzipped content // creating a new parser class to parse the unzipped content
final String contentfilename = BZip2Utils.getUncompressedFilename(location.getFileName()); final String contentfilename = BZip2Utils.getUncompressedFileName(location.getFileName());
final String mime = TextParser.mimeOf(MultiProtocolURL.getFileExtension(contentfilename)); final String mime = TextParser.mimeOf(MultiProtocolURL.getFileExtension(contentfilename));
final Document[] docs = TextParser.parseSource(location, mime, null, defaultValency, valencySwitchTagNames, scraper, timezoneOffset, 999, tempFile); final Document[] docs = TextParser.parseSource(location, mime, null, defaultValency, valencySwitchTagNames, scraper, timezoneOffset, 999, tempFile);
if (docs != null) maindoc.addSubDocuments(docs); if (docs != null) maindoc.addSubDocuments(docs);
@ -197,7 +197,7 @@ public class bzipParser extends AbstractParser implements Parser {
final InputStream compressedInStream, final int maxLinks, final long maxBytes) throws Failure { final InputStream compressedInStream, final int maxLinks, final long maxBytes) throws Failure {
// creating a new parser class to parse the unzipped content // creating a new parser class to parse the unzipped content
final String compressedFileName = location.getFileName(); final String compressedFileName = location.getFileName();
final String contentfilename = BZip2Utils.getUncompressedFilename(compressedFileName); final String contentfilename = BZip2Utils.getUncompressedFileName(compressedFileName);
final String mime = TextParser.mimeOf(MultiProtocolURL.getFileExtension(contentfilename)); final String mime = TextParser.mimeOf(MultiProtocolURL.getFileExtension(contentfilename));
try { try {
/* Use the uncompressed file name for sub parsers to not unnecessarily use again the gzipparser */ /* Use the uncompressed file name for sub parsers to not unnecessarily use again the gzipparser */
@ -212,6 +212,7 @@ public class bzipParser extends AbstractParser implements Parser {
} }
} }
@SuppressWarnings("resource")
@Override @Override
public Document[] parseWithLimits(final DigestURL location, final String mimeType, final String charset, final VocabularyScraper scraper, public Document[] parseWithLimits(final DigestURL location, final String mimeType, final String charset, final VocabularyScraper scraper,
final int timezoneOffset, final InputStream source, final int maxLinks, final long maxBytes) final int timezoneOffset, final InputStream source, final int maxLinks, final long maxBytes)
@ -221,7 +222,6 @@ public class bzipParser extends AbstractParser implements Parser {
try { try {
// BZip2CompressorInputStream checks filecontent (magic start-bytes "BZh") and throws ioexception if no match // BZip2CompressorInputStream checks filecontent (magic start-bytes "BZh") and throws ioexception if no match
zippedContent = new BZip2CompressorInputStream(source); zippedContent = new BZip2CompressorInputStream(source);
} catch(Exception e) { } catch(Exception e) {
throw new Parser.Failure("Unexpected error while parsing bzip file. " + e.getMessage(), location); throw new Parser.Failure("Unexpected error while parsing bzip file. " + e.getMessage(), location);
} }

@ -146,6 +146,7 @@ public class docParser extends AbstractParser implements Parser {
* @return an array containing one Document * @return an array containing one Document
* @throws net.yacy.document.Parser.Failure * @throws net.yacy.document.Parser.Failure
*/ */
@SuppressWarnings("resource")
public Document[] parseOldWordDoc( public Document[] parseOldWordDoc(
final DigestURL location, final DigestURL location,
final String mimeType, final String mimeType,

@ -128,7 +128,7 @@ public class gzipParser extends AbstractParser implements Parser {
try { try {
maindoc = createMainDocument(location, mimeType, charset, this); maindoc = createMainDocument(location, mimeType, charset, this);
// creating a new parser class to parse the unzipped content // creating a new parser class to parse the unzipped content
final String contentfilename = GzipUtils.getUncompressedFilename(location.getFileName()); final String contentfilename = GzipUtils.getUncompressedFileName(location.getFileName());
final String mime = TextParser.mimeOf(MultiProtocolURL.getFileExtension(contentfilename)); final String mime = TextParser.mimeOf(MultiProtocolURL.getFileExtension(contentfilename));
Document[] docs = TextParser.parseSource(location, mime, null, defaultValency, valencySwitchTagNames, scraper, timezoneOffset, DEFAULT_DEPTH, tempFile); Document[] docs = TextParser.parseSource(location, mime, null, defaultValency, valencySwitchTagNames, scraper, timezoneOffset, DEFAULT_DEPTH, tempFile);
if (docs != null) maindoc.addSubDocuments(docs); if (docs != null) maindoc.addSubDocuments(docs);
@ -195,7 +195,7 @@ public class gzipParser extends AbstractParser implements Parser {
final InputStream compressedInStream, final int maxLinks, final long maxBytes) throws Failure { final InputStream compressedInStream, final int maxLinks, final long maxBytes) throws Failure {
// creating a new parser class to parse the unzipped content // creating a new parser class to parse the unzipped content
final String compressedFileName = location.getFileName(); final String compressedFileName = location.getFileName();
final String contentfilename = GzipUtils.getUncompressedFilename(compressedFileName); final String contentfilename = GzipUtils.getUncompressedFileName(compressedFileName);
final String mime = TextParser.mimeOf(MultiProtocolURL.getFileExtension(contentfilename)); final String mime = TextParser.mimeOf(MultiProtocolURL.getFileExtension(contentfilename));
try { try {
/* Use the uncompressed file name for sub parsers to not unnecessarily use again the gzipparser */ /* Use the uncompressed file name for sub parsers to not unnecessarily use again the gzipparser */

@ -57,7 +57,6 @@ import com.drew.metadata.exif.GpsDirectory;
import net.yacy.cora.document.id.AnchorURL; import net.yacy.cora.document.id.AnchorURL;
import net.yacy.cora.document.id.DigestURL; import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.document.id.MultiProtocolURL; import net.yacy.cora.document.id.MultiProtocolURL;
import net.yacy.cora.federate.solr.connector.SolrServerConnector;
import net.yacy.cora.util.ConcurrentLog; import net.yacy.cora.util.ConcurrentLog;
import net.yacy.document.AbstractParser; import net.yacy.document.AbstractParser;
import net.yacy.document.Document; import net.yacy.document.Document;

@ -109,6 +109,7 @@ public class odtParser extends AbstractParser implements Parser {
return parser; return parser;
} }
@SuppressWarnings("resource")
private Document[] parse(final DigestURL location, final String mimeType, @SuppressWarnings("unused") final String charset, final File dest) private Document[] parse(final DigestURL location, final String mimeType, @SuppressWarnings("unused") final String charset, final File dest)
throws Parser.Failure, InterruptedException { throws Parser.Failure, InterruptedException {

@ -221,6 +221,7 @@ public class pdfParser extends AbstractParser implements Parser {
/** /**
* Clean up cache resources allocated by PDFBox that would otherwise not be released. * Clean up cache resources allocated by PDFBox that would otherwise not be released.
*/ */
@SuppressWarnings("deprecation")
public static void clearPdfBoxCaches() { public static void clearPdfBoxCaches() {
/* /*
* Prior to pdfbox 2.0.0 font cache occupied > 80MB RAM for a single pdf and * Prior to pdfbox 2.0.0 font cache occupied > 80MB RAM for a single pdf and

@ -9,6 +9,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -169,8 +171,8 @@ public class RDFaParser extends AbstractParser implements Parser {
} }
} else { } else {
try { try {
aURL = new URL(args[0]); aURL = new URI(args[0]).toURL();
} catch (final MalformedURLException e) { } catch (final MalformedURLException | URISyntaxException e) {
System.err.println("URL is malformed."); System.err.println("URL is malformed.");
} }

@ -97,7 +97,7 @@ public class tarParser extends AbstractParser implements Parser {
while (true) { while (true) {
try { try {
File tmp = null; File tmp = null;
entry = tis.getNextTarEntry(); entry = tis.getNextEntry();
if (entry == null) break; if (entry == null) break;
if (entry.isDirectory() || entry.getSize() <= 0) continue; if (entry.isDirectory() || entry.getSize() <= 0) continue;
final String name = entry.getName(); final String name = entry.getName();
@ -154,7 +154,7 @@ TarArchiveEntry entry;
int totalProcessedLinks = 0; int totalProcessedLinks = 0;
while (true) { while (true) {
try { try {
entry = tis.getNextTarEntry(); entry = tis.getNextEntry();
if (entry == null) { if (entry == null) {
break; break;
} }

@ -38,7 +38,6 @@ import java.awt.event.ActionListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;

@ -30,8 +30,6 @@ package net.yacy.htroot;
import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.Parser; import net.yacy.document.Parser;
import net.yacy.document.TextParser; import net.yacy.document.TextParser;
import net.yacy.document.parser.pdfParser;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants; import net.yacy.search.SwitchboardConstants;
import net.yacy.server.serverObjects; import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch; import net.yacy.server.serverSwitch;
@ -42,8 +40,6 @@ public class ConfigParser_p {
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) { public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
// return variable that accumulates replacements // return variable that accumulates replacements
final serverObjects prop = new serverObjects(); final serverObjects prop = new serverObjects();
final Switchboard sb = (Switchboard) env;
if (post != null) { if (post != null) {

@ -22,6 +22,8 @@ package net.yacy.htroot;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.channels.Channels; import java.nio.channels.Channels;
@ -83,7 +85,7 @@ public class IndexImportJsonList_p {
*/ */
if (urlstr != null && urlstr.length() > 0) { if (urlstr != null && urlstr.length() > 0) {
try { try {
final URL url = new URL(urlstr); final URL url = new URI(urlstr).toURL();
final String tempfilename = "jsonlistimporter"; final String tempfilename = "jsonlistimporter";
final boolean gz = urlstr.endsWith(".gz"); final boolean gz = urlstr.endsWith(".gz");
final File tempfile = File.createTempFile(tempfilename, ""); final File tempfile = File.createTempFile(tempfilename, "");
@ -93,7 +95,7 @@ public class IndexImportJsonList_p {
final JsonListImporter wi = new JsonListImporter(tempfile, gz, true); final JsonListImporter wi = new JsonListImporter(tempfile, gz, true);
wi.start(); wi.start();
prop.put("import_thread", "started"); prop.put("import_thread", "started");
} catch (final IOException ex) { } catch (final IOException | URISyntaxException ex) {
prop.put("import_thread", ex.getMessage()); prop.put("import_thread", ex.getMessage());
} }
prop.put("import", 1); prop.put("import", 1);

@ -3,6 +3,7 @@ package net.yacy.htroot.api;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -46,7 +47,7 @@ public class ynetSearch {
s = s + "&" + k.getKey() + "=" + k.getValue(); s = s + "&" + k.getKey() + "=" + k.getValue();
} }
// final String s = searchaddress+"&query="+post.get("search")+"&maximumRecords="+post.get("maximumRecords")+"&startRecord="+post.get("startRecord"); // final String s = searchaddress+"&query="+post.get("search")+"&maximumRecords="+post.get("maximumRecords")+"&startRecord="+post.get("startRecord");
final URL url = new URL(s); final URL url = new URI(s).toURL();
is = url.openStream(); is = url.openStream();
Scanner scanner = new Scanner(is); Scanner scanner = new Scanner(is);
final String httpout = scanner.useDelimiter( "\\Z" ).next(); final String httpout = scanner.useDelimiter( "\\Z" ).next();

@ -102,7 +102,7 @@ public class InetPathAccessHandler extends InetAccessHandler {
final String path = (idx > 0 && (pattern.length() > idx + 1)) ? pattern.substring(idx + 1) : "/*"; final String path = (idx > 0 && (pattern.length() > idx + 1)) ? pattern.substring(idx + 1) : "/*";
if (!addr.isEmpty()) { if (!addr.isEmpty()) {
final PathSpec pathSpec = PathMappings.asPathSpec(path); final PathSpec pathSpec = PathSpec.from(path);
InetAddressSet addresses = pathMappings.get(pathSpec); InetAddressSet addresses = pathMappings.get(pathSpec);
if (addresses == null) { if (addresses == null) {
addresses = new InetAddressSet(); addresses = new InetAddressSet();

@ -24,7 +24,6 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import net.yacy.ai.OllamaClient;
import net.yacy.ai.OpenAIClient; import net.yacy.ai.OpenAIClient;
import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector; import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector;
import net.yacy.search.Switchboard; import net.yacy.search.Switchboard;
@ -51,12 +50,8 @@ import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** /**
* This class implements a Retrieval Augmented Generation ("RAG") proxy which uses a YaCy search index * This class implements a Retrieval Augmented Generation ("RAG") proxy which uses a YaCy search index
@ -66,11 +61,11 @@ public class RAGProxyServlet extends HttpServlet {
private static final long serialVersionUID = 3411544789759603107L; private static final long serialVersionUID = 3411544789759603107L;
private static Boolean LLM_ENABLED = false; //private static Boolean LLM_ENABLED = false;
private static Boolean LLM_CONTROL_OLLAMA = true; //private static Boolean LLM_CONTROL_OLLAMA = true;
private static Boolean LLM_ATTACH_QUERY = false; // instructs the proxy to attach the prompt generated to do the RAG search //private static Boolean LLM_ATTACH_QUERY = false; // instructs the proxy to attach the prompt generated to do the RAG search
private static Boolean LLM_ATTACH_REFERENCES = false; // instructs the proxy to attach a list of sources that had been used in RAG //private static Boolean LLM_ATTACH_REFERENCES = false; // instructs the proxy to attach a list of sources that had been used in RAG
private static String LLM_LANGUAGE = "en"; // used to select proper language in RAG augmentation //private static String LLM_LANGUAGE = "en"; // used to select proper language in RAG augmentation
private static String LLM_SYSTEM_PREFIX = "\n\nYou may receive additional expert knowledge in the user prompt after a 'Additional Information' headline to enhance your knowledge. Use it only if applicable."; private static String LLM_SYSTEM_PREFIX = "\n\nYou may receive additional expert knowledge in the user prompt after a 'Additional Information' headline to enhance your knowledge. Use it only if applicable.";
private static String LLM_USER_PREFIX = "\n\nAdditional Information:\n\nbelow you find a collection of texts that might be useful to generate a response. Do not discuss these documents, just use them to answer the question above.\n\n"; private static String LLM_USER_PREFIX = "\n\nAdditional Information:\n\nbelow you find a collection of texts that might be useful to generate a response. Do not discuss these documents, just use them to answer the question above.\n\n";
private static String LLM_API_HOST = "http://localhost:11434"; // Ollama port; install ollama from https://ollama.com/ private static String LLM_API_HOST = "http://localhost:11434"; // Ollama port; install ollama from https://ollama.com/

@ -37,7 +37,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -58,7 +57,6 @@ import net.yacy.cora.util.ConcurrentLog;
import net.yacy.crawler.retrieval.Response; import net.yacy.crawler.retrieval.Response;
import net.yacy.document.SentenceReader; import net.yacy.document.SentenceReader;
import net.yacy.document.Tokenizer; import net.yacy.document.Tokenizer;
import net.yacy.document.parser.pdfParser;
import net.yacy.document.parser.html.ContentScraper; import net.yacy.document.parser.html.ContentScraper;
import net.yacy.document.parser.html.IconEntry; import net.yacy.document.parser.html.IconEntry;
import net.yacy.document.parser.html.IconLinkRelations; import net.yacy.document.parser.html.IconLinkRelations;

@ -86,6 +86,7 @@ public final class RowHandleMap implements HandleMap, Iterable<Map.Entry<byte[],
* @throws IOException * @throws IOException
* @throws SpaceExceededException * @throws SpaceExceededException
*/ */
@SuppressWarnings("resource")
public RowHandleMap(final int keylength, final ByteOrder objectOrder, final int idxbytes, final File file) throws IOException, SpaceExceededException { public RowHandleMap(final int keylength, final ByteOrder objectOrder, final int idxbytes, final File file) throws IOException, SpaceExceededException {
this(keylength, objectOrder, idxbytes, (int) (file.length() / (keylength + idxbytes)), file.getAbsolutePath()); this(keylength, objectOrder, idxbytes, (int) (file.length() / (keylength + idxbytes)), file.getAbsolutePath());
// read the index dump and fill the index // read the index dump and fill the index
@ -95,10 +96,11 @@ public final class RowHandleMap implements HandleMap, Iterable<Map.Entry<byte[],
fis = new FileInputStream(file); fis = new FileInputStream(file);
is = new BufferedInputStream(fis, 1024 * 1024); is = new BufferedInputStream(fis, 1024 * 1024);
} catch (final OutOfMemoryError e) { } catch (final OutOfMemoryError e) {
if(fis != null) { if (fis != null) {
/* Reuse if possible the already created FileInputStream */ /* Reuse if possible the already created FileInputStream */
is = fis; is = fis;
} else { } else {
// fis is null, no resource to close
is = new FileInputStream(file); is = new FileInputStream(file);
} }
} }

@ -236,7 +236,7 @@ public class ThreadDump extends HashMap<ThreadDump.StackTrace, List<String>> imp
while (tracename.length() < 20) tracename = tracename + "_"; while (tracename.length() < 20) tracename = tracename + "_";
tracename = "[" + tracename + "] "; tracename = "[" + tracename + "] ";
} }
final String threadtitle = tracename + "Thread= " + thread.getName() + " " + (thread.isDaemon()?"daemon":"") + " id=" + thread.getId() + " " + thread.getState().toString(); final String threadtitle = tracename + "Thread= " + thread.getName() + " " + (thread.isDaemon()?"daemon":"") + " id=" + thread.threadId() + " " + thread.getState().toString();
String className; String className;
boolean cutcore = true; boolean cutcore = true;
for (int i = 0; i < stackTraceElements.length; i++) { for (int i = 0; i < stackTraceElements.length; i++) {

@ -42,7 +42,7 @@ import java.util.Locale;
public final class Formatter { public final class Formatter {
// default formatter // default formatter
private static Locale locale = new Locale("en"); private static Locale locale = Locale.forLanguageTag("en");
/** /**
* use ThreadLocal to generate new formatter for each Thread since NumberFormat is not synchronized * use ThreadLocal to generate new formatter for each Thread since NumberFormat is not synchronized
*/ */
@ -78,7 +78,7 @@ public final class Formatter {
*/ */
public static void setLocale(final String lang) { public static void setLocale(final String lang) {
final String l = (lang.equalsIgnoreCase("default") ? "en" : lang.toLowerCase(Locale.ROOT)); final String l = (lang.equalsIgnoreCase("default") ? "en" : lang.toLowerCase(Locale.ROOT));
setLocale(l.equals("none") ? null : new Locale(l)); setLocale(l.equals("none") ? null : Locale.forLanguageTag(l));
} }

@ -122,7 +122,7 @@ public final class OS {
FileUtils.copy(UTF8.getBytes(theScript), scriptFile); FileUtils.copy(UTF8.getBytes(theScript), scriptFile);
if(!isWindows){ // set executable if(!isWindows){ // set executable
try { try {
Runtime.getRuntime().exec("chmod 755 " + scriptFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor(); Runtime.getRuntime().exec(new String[]{"chmod", "755", scriptFile.getAbsolutePath().replaceAll(" ", "\\ ")}).waitFor();
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
ConcurrentLog.severe("DEPLOY", "deploy of script file failed. file = " + scriptFile.getAbsolutePath(), e); ConcurrentLog.severe("DEPLOY", "deploy of script file failed. file = " + scriptFile.getAbsolutePath(), e);
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
@ -155,7 +155,7 @@ public final class OS {
final File starterFile = new File(scriptFile.getAbsolutePath().replaceAll(" ", "\\ ") + starterFileExtension); final File starterFile = new File(scriptFile.getAbsolutePath().replaceAll(" ", "\\ ") + starterFileExtension);
deployScript(starterFile, script); deployScript(starterFile, script);
try { try {
Runtime.getRuntime().exec(starterFile.getAbsolutePath().replaceAll(" ", "\\ ")).waitFor(); Runtime.getRuntime().exec(new String[] {starterFile.getAbsolutePath().replaceAll(" ", "\\ ")}).waitFor();
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
throw new IOException(e.getMessage()); throw new IOException(e.getMessage());
} }

@ -47,6 +47,8 @@ import java.io.IOException;
import java.net.Inet6Address; import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.text.ParseException; import java.text.ParseException;
import java.time.DateTimeException; import java.time.DateTimeException;
@ -1358,7 +1360,7 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>
return "wrong protocol for seedURL"; return "wrong protocol for seedURL";
} }
try { try {
final URL url = new URL(seedURL); final URL url = new URI(seedURL).toURL();
final String host = url.getHost(); final String host = url.getHost();
if (Domains.isIntranet(host)) { if (Domains.isIntranet(host)) {
// network.unit.domain = any returns isIntranet() always true (because noLocalCheck is set true) // network.unit.domain = any returns isIntranet() always true (because noLocalCheck is set true)
@ -1371,7 +1373,7 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>
return "seedURL in local network rejected ("+host+")"; return "seedURL in local network rejected ("+host+")";
} }
} }
} catch (final MalformedURLException e ) { } catch (final MalformedURLException | URISyntaxException e ) {
return "seedURL malformed"; return "seedURL malformed";
} }
} }

@ -728,7 +728,7 @@ public final class Switchboard extends serverSwitch {
// Set jvm default locale to match UI language ( // Set jvm default locale to match UI language (
String lng = this.getConfig("locale.language", "en"); String lng = this.getConfig("locale.language", "en");
if (!"browser".equals(lng) && !"default".equals(lng)) { if (!"browser".equals(lng) && !"default".equals(lng)) {
Locale.setDefault(new Locale(lng)); Locale.setDefault(Locale.forLanguageTag(lng));
} else { } else {
lng = "en"; // default = English lng = "en"; // default = English
} }

@ -63,7 +63,8 @@ public abstract class SingleDocumentMatcher {
final SolrQueryRequestBase solrRequest = new SolrQueryRequestBase(targetCore, solrQuery) { final SolrQueryRequestBase solrRequest = new SolrQueryRequestBase(targetCore, solrQuery) {
}; };
final LuceneQParserPlugin luceneParserPlugin = new LuceneQParserPlugin(); @SuppressWarnings("resource")
final LuceneQParserPlugin luceneParserPlugin = new LuceneQParserPlugin();
final QParser solrParser = luceneParserPlugin.createParser(query, null, solrRequest.getParams(), solrRequest); final QParser solrParser = luceneParserPlugin.createParser(query, null, solrRequest.getParams(), solrRequest);
return solrParser.parse(); return solrParser.parse();
} }

@ -24,7 +24,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.apache.poi.ss.formula.atp.DateParser; import org.apache.poi.ss.util.DateParser;
import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;

@ -126,7 +126,7 @@ public class tarTools {
if (new File(untarDir).exists()) { if (new File(untarDir).exists()) {
final TarArchiveInputStream tin = new TarArchiveInputStream(in); final TarArchiveInputStream tin = new TarArchiveInputStream(in);
try { try {
TarArchiveEntry tarEntry = tin.getNextTarEntry(); TarArchiveEntry tarEntry = tin.getNextEntry();
if (tarEntry == null) { if (tarEntry == null) {
throw new IOException("tar archive is empty or corrupted"); throw new IOException("tar archive is empty or corrupted");
} }
@ -143,7 +143,7 @@ public class tarTools {
} else { } else {
destPath.mkdir(); destPath.mkdir();
} }
tarEntry = tin.getNextTarEntry(); tarEntry = tin.getNextEntry();
} }
} finally { } finally {
try { try {

@ -446,6 +446,7 @@ public class ZIMReader {
return this.blobs.get(i); return this.blobs.get(i);
} }
@SuppressWarnings("unused")
public int getSize() { public int getSize() {
return this.blobs.size(); return this.blobs.size();
} }

Loading…
Cancel
Save