Java Code Examples for org.elasticsearch.common.io.Streams#copy()
The following examples show how to use
org.elasticsearch.common.io.Streams#copy() .
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: MockAmazonS3.java From crate with Apache License 2.0 | 6 votes |
@Override public PutObjectResult putObject(final PutObjectRequest request) throws AmazonClientException { assertThat(request.getBucketName(), equalTo(bucket)); assertThat(request.getMetadata().getSSEAlgorithm(), serverSideEncryption ? equalTo("AES256") : nullValue()); assertThat(request.getCannedAcl(), notNullValue()); assertThat(request.getCannedAcl().toString(), cannedACL != null ? equalTo(cannedACL) : equalTo("private")); assertThat(request.getStorageClass(), storageClass != null ? equalTo(storageClass) : equalTo("STANDARD")); final String blobName = request.getKey(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { Streams.copy(request.getInputStream(), out); blobs.put(blobName, out.toByteArray()); } catch (IOException e) { throw new AmazonClientException(e); } return new PutObjectResult(); }
Example 2
Source File: CompressorFactory.java From Elasticsearch with Apache License 2.0 | 5 votes |
private static BytesReference uncompress(BytesReference bytes, Compressor compressor) throws IOException { StreamInput compressed = compressor.streamInput(bytes.streamInput()); BytesStreamOutput bStream = new BytesStreamOutput(); Streams.copy(compressed, bStream); compressed.close(); return bStream.bytes(); }
Example 3
Source File: FsBlobContainer.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException { final Path file = path.resolve(blobName); try (OutputStream outputStream = Files.newOutputStream(file)) { Streams.copy(inputStream, outputStream, new byte[blobStore.bufferSizeInBytes()]); } IOUtils.fsync(file, false); IOUtils.fsync(path, true); }
Example 4
Source File: IndexFeatureStore.java From elasticsearch-learning-to-rank with Apache License 2.0 | 5 votes |
private static String readResourceFile(String indexName, String resource) { try (InputStream is = IndexFeatureStore.class.getResourceAsStream(resource)) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(is, out); return out.toString(StandardCharsets.UTF_8.name()); } catch (Exception e) { LOGGER.error( (org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage( "failed to create ltr feature store index [{}] with resource [{}]", indexName, resource), e); throw new IllegalStateException("failed to create ltr feature store index with resource [" + resource + "]", e); } }
Example 5
Source File: XGBoostJsonParserTests.java From elasticsearch-learning-to-rank with Apache License 2.0 | 5 votes |
private String readModel(String model) throws IOException { try (InputStream is = this.getClass().getResourceAsStream(model)) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Streams.copy(is, bos); return bos.toString(StandardCharsets.UTF_8.name()); } }
Example 6
Source File: XmlBuilderTest.java From elasticsearch-xml with Apache License 2.0 | 5 votes |
@Test public void testParseJson() throws Exception { XmlNamespaceContext context = XmlNamespaceContext.getDefaultInstance(); context.addNamespace("bib","info:srw/cql-context-set/1/bib-v1/"); context.addNamespace("abc", "http://localhost/"); context.addNamespace("xbib", "http://xbib.org/"); context.addNamespace("lia", "http://xbib.org/namespaces/lia/"); XmlXParams params = new XmlXParams(context); InputStream in = getClass().getResourceAsStream("/test.json"); ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(in, out); byte[] buf = out.toByteArray(); String s = convertToXml(params, buf, 0, buf.length, false); assertEquals(53194, s.length()); }
Example 7
Source File: XmlBuilderTest.java From elasticsearch-xml with Apache License 2.0 | 5 votes |
@Test public void testDynamicNamespaces() throws Exception { XmlNamespaceContext context = XmlNamespaceContext.getDefaultInstance(); XmlXParams params = new XmlXParams(context); InputStream in = getClass().getResourceAsStream("/dynamic-namespace.json"); ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(in, out); byte[] buf = out.toByteArray(); String s = convertToXml(params, buf, 0, buf.length, false); assertEquals( "<root xmlns=\"http://elasticsearch.org/ns/1.0/\" xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:es=\"http://elasticsearch.org/ns/1.0/\" xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" xmlns:owl=\"http://www.w3.org/2002/07/owl#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" xmlns:xalan=\"http://xml.apache.org/xslt\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><context es:ns=\"http://example.org/\" xmlns:ns=\"http://example.org/\"/><wstxns1:foo xmlns:wstxns1=\"http://example.org/\">bar</wstxns1:foo></root>", s ); }
Example 8
Source File: CsvXContentGenerator.java From elasticsearch-rest-command with The Unlicense | 5 votes |
@Override public void writeRawField(String fieldName, InputStream content, OutputStream bos) throws IOException { generator.writeFieldName(fieldName); generator.writeRaw(':'); flush(); Streams.copy(content, bos); finishWriteRaw(); }
Example 9
Source File: DetectLanguageTests.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 5 votes |
private void testLanguage(String path, String lang) throws Exception { Reader reader = new InputStreamReader(getClass().getResourceAsStream(path), StandardCharsets.UTF_8); Writer writer = new StringWriter(); Streams.copy(reader, writer); reader.close(); writer.close(); LangdetectService detect = new LangdetectService(); assertEquals(lang, detect.detectAll(writer.toString()).get(0).getLanguage()); }
Example 10
Source File: BaseClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
public void mapping(String type, InputStream in) throws IOException { if (type == null) { return; } StringWriter sw = new StringWriter(); Streams.copy(new InputStreamReader(in), sw); mappings.put(type, sw.toString()); }
Example 11
Source File: EnterpriseLicense.java From crate with Apache License 2.0 | 5 votes |
private static byte[] publicKey() { try (InputStream is = EnterpriseLicenseService.class.getResourceAsStream("/public.key")) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(is, out); return out.toByteArray(); } catch (IOException ex) { throw new IllegalStateException(ex); } catch (NullPointerException e) { throw new IllegalStateException("The CrateDB distribution is missing its public key", e); } }
Example 12
Source File: LicenseServiceTest.java From crate with Apache License 2.0 | 5 votes |
private static byte[] getPrivateKey() { try (InputStream is = LicenseServiceTest.class.getResourceAsStream("/private.key")) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(is, out); return out.toByteArray(); } catch (IOException ex) { throw new IllegalStateException(ex); } }
Example 13
Source File: AbstractLegacyBlobContainer.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException { try (OutputStream stream = createOutput(blobName)) { Streams.copy(inputStream, stream); } }