Remove usage of Streams.copyToBytesFromClasspath()

Original commit: elastic/x-pack-elasticsearch@8f813e9275
This commit is contained in:
Tanguy Leroux 2015-07-31 13:01:56 +02:00
parent 3713b3dfdd
commit 101ea6deab
4 changed files with 12 additions and 14 deletions

View File

@ -460,8 +460,8 @@ public class HttpESExporter extends AbstractExporter<HttpESExporter> implements
*/
private boolean checkAndUploadIndexTemplate(final String host) {
byte[] template;
try {
template = Streams.copyToBytesFromClasspath("/marvel_index_template.json");
try (InputStream is = getClass().getResourceAsStream("/marvel_index_template.json")) {
template = ByteStreams.toByteArray(is);
} catch (IOException e) {
// throwing an exception to stop exporting process - we don't want to send data unless
// we put in the template for it.

View File

@ -5,14 +5,13 @@
*/
package org.elasticsearch.shield;
import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
@ -27,10 +26,9 @@ public class ShieldBuild {
String hashShort = "NA";
String timestamp = "NA";
try {
String properties = Streams.copyToStringFromClasspath("/shield-build.properties");
try (InputStream is = ShieldBuild.class.getResourceAsStream("/shield-build.properties")) {
Properties props = new Properties();
props.load(new FastStringReader(properties));
props.load(is);
hash = props.getProperty("hash", hash);
if (!hash.equals("NA")) {
hashShort = hash.substring(0, 7);

View File

@ -7,6 +7,7 @@ package org.elasticsearch.shield.audit.index;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
@ -53,6 +54,7 @@ import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@ -641,8 +643,8 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail {
}
void putTemplate(Settings customSettings) {
try {
final byte[] template = Streams.copyToBytesFromClasspath("/" + INDEX_TEMPLATE_NAME + ".json");
try (InputStream is = getClass().getResourceAsStream("/" + INDEX_TEMPLATE_NAME + ".json")) {
final byte[] template = ByteStreams.toByteArray(is);
PutIndexTemplateRequest request = new PutIndexTemplateRequest(INDEX_TEMPLATE_NAME).source(template);
if (customSettings != null && customSettings.names().size() > 0) {
Settings updatedSettings = Settings.builder()

View File

@ -5,14 +5,13 @@
*/
package org.elasticsearch.watcher;
import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
@ -27,10 +26,9 @@ public class WatcherBuild {
String hashShort = "NA";
String timestamp = "NA";
try {
String properties = Streams.copyToStringFromClasspath("/watcher-build.properties");
try (InputStream is = WatcherBuild.class.getResourceAsStream("/watcher-build.properties")) {
Properties props = new Properties();
props.load(new FastStringReader(properties));
props.load(is);
hash = props.getProperty("hash", hash);
if (!hash.equals("NA")) {
hashShort = hash.substring(0, 7);