Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Splunk SDK for Java Changelog

## Version 1.6.5

### Bug Fixes

* Fixed bug for push back buffer is full when exporting data in XML (GitHub PR [#125](https://github.com/splunk/splunk-sdk-java/pull/125)).

## Version 1.6.4

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/splunk/splunk-sdk-java.svg?branch=master)](https://travis-ci.org/splunk/splunk-sdk-java)
# The Splunk Software Development Kit for Java

#### Version 1.6.4
#### Version 1.6.5

The Splunk Software Development Kit (SDK) for Java contains library code and
examples designed to enable developers to build applications using Splunk.
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<project name="splunk-sdk-java" basedir="." default="dist" xmlns:jacoco="antlib:org.jacoco.ant"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="antlib:org.jacoco.ant ">
<property name="version.number" value="1.6.4"/>
<property name="version.number" value="1.6.5"/>

<!-- Paths within the repository that are referenced
multiple times. -->
Expand Down
2 changes: 1 addition & 1 deletion deploy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare -r scriptDirectory="$(dirname $(readlink -e $0))"
declare -r scriptName="$(basename $0)"
declare -r version="1.6.4"
declare -r version="1.6.5"

if [[ $# -ne 1 ]]; then
echo 1>&2 "Usage: ${scriptName} {local|staging||production}"
Expand Down
30 changes: 15 additions & 15 deletions deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ deploy \<repository-name>

##DESCRIPTION

Deploy transmits **dist/splunk-1.6.4.jar**, **dist/splunk-1.6.4-javadoc.jar**, and
**dist/splunk-1.6.4-sources.jar** to the **local**, **staging**, or **production**
Deploy transmits **dist/splunk-1.6.5.jar**, **dist/splunk-1.6.5-javadoc.jar**, and
**dist/splunk-1.6.5-sources.jar** to the **local**, **staging**, or **production**
maven repository. Repository names are mapped to locations as follows.

| repository-name | location |
Expand All @@ -21,18 +21,18 @@ maven repository. Repository names are mapped to locations as follows.

After deployment you should find this tree structure at the location of your repository

com/splunk/splunk/1.6.4/
├── splunk-1.6.4-javadoc.jar
├── splunk-1.6.4-javadoc.jar.md5
├── splunk-1.6.4-javadoc.jar.sha1
├── splunk-1.6.4-sources.jar
├── splunk-1.6.4-sources.jar.md5
├── splunk-1.6.4-sources.jar.sha1
├── splunk-1.6.4.jar
├── splunk-1.6.4.jar.md5
├── splunk-1.6.4.jar.sha1
├── splunk-1.6.4.pom
├── splunk-1.6.4.pom.md5
└── splunk-1.6.4.pom.sha1
com/splunk/splunk/1.6.5/
├── splunk-1.6.5-javadoc.jar
├── splunk-1.6.5-javadoc.jar.md5
├── splunk-1.6.5-javadoc.jar.sha1
├── splunk-1.6.5-sources.jar
├── splunk-1.6.5-sources.jar.md5
├── splunk-1.6.5-sources.jar.sha1
├── splunk-1.6.5.jar
├── splunk-1.6.5.jar.md5
├── splunk-1.6.5.jar.sha1
├── splunk-1.6.5.pom
├── splunk-1.6.5.pom.md5
└── splunk-1.6.5.pom.sha1

Verify this structure prior to release.
2 changes: 1 addition & 1 deletion splunk/com/splunk/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean verify(String s, SSLSession sslSession) {
private String prefix = null;

static Map<String, String> defaultHeader = new HashMap<String, String>() {{
put("User-Agent", "splunk-sdk-java/1.6.4");
put("User-Agent", "splunk-sdk-java/1.6.5");
put("Accept", "*/*");
}};

Expand Down
74 changes: 50 additions & 24 deletions splunk/com/splunk/InsertRootElementFilterInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
package com.splunk;

import java.io.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.Callable;

/**
* Takes an InputStream containing a UTF-8 encoded XML document containing one or more
Expand All @@ -31,22 +28,35 @@
* it is filtering.
*/
class InsertRootElementFilterInputStream extends FilterInputStream {
private static final int REREAD_BUFFER_SIZE = 512;
private static byte[] resultsTagBytes;
private final ByteArrayInputStream suffix = new ByteArrayInputStream("</doc>".getBytes("UTF-8"));
private ByteArrayInputStream beforeResultsBuffer;
private boolean wrotePrefix;

private byte[] oneByte = new byte[1];

static {
try {
resultsTagBytes = "results".getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
//should not be thrown because UTF-8 is supported
throw new RuntimeException(e);
}
}

InsertRootElementFilterInputStream(InputStream in) throws IOException {
// Wrap in with a pushback stream so we can write our modified version back
// onto the beginning of it.
super(new PushbackInputStream(in, 512));
super(new PushbackInputStream(in, REREAD_BUFFER_SIZE));

PushbackInputStream pin = (PushbackInputStream)this.in;

// Read bytes until we reach '>', then push everything we read, followed by "<doc>",
// back onto the stream. If we run out of input before we reach '>', then don't
// modify the stream.
ByteArrayOutputStream beforeResultsChars = new ByteArrayOutputStream();
ByteArrayOutputStream atResultsChars = new ByteArrayOutputStream();
beforeResultsBuffer = new ByteArrayInputStream(new byte[0]);

int ch;
while (true) {
Expand All @@ -57,32 +67,19 @@ class InsertRootElementFilterInputStream extends FilterInputStream {
pin.unread(beforeResultsChars.toByteArray());
return;
} else if (ch == (int)'<') {
// Try extending
atResultsChars.reset();
int ech;
boolean matched = true;
for (byte b : "results".getBytes("UTF-8")) {
ech = this.in.read();
atResultsChars.write(ech);
if (ech != b) {
// Extension failed. Put the bytes back on and search again.
pin.unread(atResultsChars.toByteArray());
matched = false;
break;
}
}
boolean resultsTag = isResultsTag(pin);

if (matched) {
if (resultsTag) {
// If we reach here, the extension succeeded, so we insert <doc>, unread everything,
// and return.

// Unread the match.
pin.unread(atResultsChars.toByteArray());
pin.unread(InsertRootElementFilterInputStream.resultsTagBytes);
// Unread the opening '<' that led to our extension
pin.unread(ch);
// Add a '<doc>' element to our read charactes and unread them.
// Add a '<doc>' element to our read characters
beforeResultsChars.write("<doc>".getBytes("UTF-8"));
pin.unread(beforeResultsChars.toByteArray());
beforeResultsBuffer = new ByteArrayInputStream(beforeResultsChars.toByteArray());
wrotePrefix = true;
return;
} else {
Expand All @@ -96,9 +93,38 @@ class InsertRootElementFilterInputStream extends FilterInputStream {
}
}

private boolean isResultsTag(PushbackInputStream pin) throws IOException {
// Try extending
ByteArrayOutputStream atResultsChars = new ByteArrayOutputStream();
int ech;
boolean resultsTag = true;
for (byte b : resultsTagBytes) {
ech = this.in.read();
atResultsChars.write(ech);
if (ech != b) {
// Extension failed. Put the bytes back on and search again.
pin.unread(atResultsChars.toByteArray());
resultsTag = false;
break;
}
}
return resultsTag;
}

@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
int result = in.read(buffer, offset, length);
// first we read from the buffer before the first results xml tag
int result = 0;
int availableFromBuffer = beforeResultsBuffer.available();
if (offset < availableFromBuffer) {
result = beforeResultsBuffer.read(buffer, offset, length);
if (length <= result) {
return result;
}
}

// then we read from the original input stream
result += in.read(buffer, offset+result, length-result);
if (result == -1 && wrotePrefix) {
// No more bytes to read from in, and we have written '<doc>' earlier in the stream
return suffix.read(buffer, offset, length);
Expand Down
Loading