Skip to content

Commit

Permalink
Merge pull request #146 from project-husky/develop
Browse files Browse the repository at this point in the history
Migrate fix for release 2.5.0
  • Loading branch information
ralych authored Jul 5, 2024
2 parents d59d34f + e4e688b commit 7b4f81a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.projecthusky.valueset.model.ValueSet;
import org.projecthusky.valueset.model.ValueSetEntry;
import org.projecthusky.valueset.model.Version;
import org.projecthusky.valueset.utils.VsUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -147,7 +148,7 @@ public ValueSet downloadValueSet(ValueSetConfig valueSetConfig)
var sourceUrlString = valueSetConfig.getSourceUrl();
var downloadedString = "";
try {
downloadedString = IOUtils.toString(new URL(sourceUrlString), StandardCharsets.UTF_8);
downloadedString = VsUtils.downloadAsString(new URL(sourceUrlString));
downloadedString = downloadedString.replace("&lt;", "<");
downloadedString = downloadedString.replace("&gt;", ">");
downloadedString = downloadedString.replace("&amp;", "&");
Expand Down Expand Up @@ -196,7 +197,7 @@ public ValueSet downloadValueSet(ValueSetConfig valueSetConfig)
public byte[] downloadValueSetRaw(ValueSetConfig valueSetConfig) throws IOException {
byte[] retVal = null;
if (valueSetConfig != null && SourceSystemType.ARTDECOR_FHIR.equals(valueSetConfig.getSourceSystemType())) {
retVal = IOUtils.toByteArray(new URL(valueSetConfig.getSourceUrl()));
retVal = VsUtils.downloadAsByteArray(new URL(valueSetConfig.getSourceUrl()));
}
return retVal;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
*
*/
package org.projecthusky.valueset.utils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;

/**
*
*/
public class VsUtils {

/**
* Method to download as a string
*
* @param url
* the url to download form
* @return the string of the downloaded content
* @throws IOException
* occures on errors during download
*/
public static String downloadAsString(URL url) throws IOException {
URLConnection connection = url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 Gecko/20100316 Firefox/3.6.2");
InputStream is = connection.getInputStream();
String downloadedString = IOUtils.toString(is, StandardCharsets.UTF_8);
return downloadedString;
}

/**
* Method to download as a byte array
*
* @param url
* the url to download form
* @return the byte array of the downloaded content
* @throws IOException
* occures on errors during download
*/
public static byte[] downloadAsByteArray(URL url) throws IOException {
URLConnection connection = url.openConnection();
connection.setRequestProperty("User-Agent",
"Mozilla/5.0 Gecko/20100316 Firefox/3.6.2");
InputStream is = connection.getInputStream();
byte[] downloadedBytes = IOUtils.toByteArray(is, is.available());
return downloadedBytes;
}

}

0 comments on commit 7b4f81a

Please sign in to comment.