Skip to content

Commit 308dc65

Browse files
authored
Merge pull request #129 from splunk/release/1.6.5
Release/1.6.5
2 parents a6d7e9c + 38a7696 commit 308dc65

File tree

8 files changed

+256
-46
lines changed

8 files changed

+256
-46
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Splunk SDK for Java Changelog
22

3+
## Version 1.6.5
4+
5+
### Bug Fixes
6+
7+
* 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)).
8+
39
## Version 1.6.4
410

511
### Bug Fixes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Build Status](https://travis-ci.org/splunk/splunk-sdk-java.svg?branch=master)](https://travis-ci.org/splunk/splunk-sdk-java)
22
# The Splunk Software Development Kit for Java
33

4-
#### Version 1.6.4
4+
#### Version 1.6.5
55

66
The Splunk Software Development Kit (SDK) for Java contains library code and
77
examples designed to enable developers to build applications using Splunk.

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

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

2323
<!-- Paths within the repository that are referenced
2424
multiple times. -->

deploy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare -r scriptDirectory="$(dirname $(readlink -e $0))"
44
declare -r scriptName="$(basename $0)"
5-
declare -r version="1.6.4"
5+
declare -r version="1.6.5"
66

77
if [[ $# -ne 1 ]]; then
88
echo 1>&2 "Usage: ${scriptName} {local|staging||production}"

deploy.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ deploy \<repository-name>
99

1010
##DESCRIPTION
1111

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

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

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

24-
com/splunk/splunk/1.6.4/
25-
├── splunk-1.6.4-javadoc.jar
26-
├── splunk-1.6.4-javadoc.jar.md5
27-
├── splunk-1.6.4-javadoc.jar.sha1
28-
├── splunk-1.6.4-sources.jar
29-
├── splunk-1.6.4-sources.jar.md5
30-
├── splunk-1.6.4-sources.jar.sha1
31-
├── splunk-1.6.4.jar
32-
├── splunk-1.6.4.jar.md5
33-
├── splunk-1.6.4.jar.sha1
34-
├── splunk-1.6.4.pom
35-
├── splunk-1.6.4.pom.md5
36-
└── splunk-1.6.4.pom.sha1
24+
com/splunk/splunk/1.6.5/
25+
├── splunk-1.6.5-javadoc.jar
26+
├── splunk-1.6.5-javadoc.jar.md5
27+
├── splunk-1.6.5-javadoc.jar.sha1
28+
├── splunk-1.6.5-sources.jar
29+
├── splunk-1.6.5-sources.jar.md5
30+
├── splunk-1.6.5-sources.jar.sha1
31+
├── splunk-1.6.5.jar
32+
├── splunk-1.6.5.jar.md5
33+
├── splunk-1.6.5.jar.sha1
34+
├── splunk-1.6.5.pom
35+
├── splunk-1.6.5.pom.md5
36+
└── splunk-1.6.5.pom.sha1
3737

3838
Verify this structure prior to release.

splunk/com/splunk/HttpService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public boolean verify(String s, SSLSession sslSession) {
7373
private String prefix = null;
7474

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

splunk/com/splunk/InsertRootElementFilterInputStream.java

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
package com.splunk;
1717

1818
import java.io.*;
19-
import java.nio.ByteBuffer;
20-
import java.util.Arrays;
21-
import java.util.concurrent.Callable;
2219

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

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

39+
static {
40+
try {
41+
resultsTagBytes = "results".getBytes("UTF-8");
42+
} catch (UnsupportedEncodingException e) {
43+
//should not be thrown because UTF-8 is supported
44+
throw new RuntimeException(e);
45+
}
46+
}
47+
3948
InsertRootElementFilterInputStream(InputStream in) throws IOException {
4049
// Wrap in with a pushback stream so we can write our modified version back
4150
// onto the beginning of it.
42-
super(new PushbackInputStream(in, 512));
51+
super(new PushbackInputStream(in, REREAD_BUFFER_SIZE));
52+
4353
PushbackInputStream pin = (PushbackInputStream)this.in;
4454

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

5161
int ch;
5262
while (true) {
@@ -57,32 +67,19 @@ class InsertRootElementFilterInputStream extends FilterInputStream {
5767
pin.unread(beforeResultsChars.toByteArray());
5868
return;
5969
} else if (ch == (int)'<') {
60-
// Try extending
61-
atResultsChars.reset();
62-
int ech;
63-
boolean matched = true;
64-
for (byte b : "results".getBytes("UTF-8")) {
65-
ech = this.in.read();
66-
atResultsChars.write(ech);
67-
if (ech != b) {
68-
// Extension failed. Put the bytes back on and search again.
69-
pin.unread(atResultsChars.toByteArray());
70-
matched = false;
71-
break;
72-
}
73-
}
70+
boolean resultsTag = isResultsTag(pin);
7471

75-
if (matched) {
72+
if (resultsTag) {
7673
// If we reach here, the extension succeeded, so we insert <doc>, unread everything,
7774
// and return.
7875

7976
// Unread the match.
80-
pin.unread(atResultsChars.toByteArray());
77+
pin.unread(InsertRootElementFilterInputStream.resultsTagBytes);
8178
// Unread the opening '<' that led to our extension
8279
pin.unread(ch);
83-
// Add a '<doc>' element to our read charactes and unread them.
80+
// Add a '<doc>' element to our read characters
8481
beforeResultsChars.write("<doc>".getBytes("UTF-8"));
85-
pin.unread(beforeResultsChars.toByteArray());
82+
beforeResultsBuffer = new ByteArrayInputStream(beforeResultsChars.toByteArray());
8683
wrotePrefix = true;
8784
return;
8885
} else {
@@ -96,9 +93,38 @@ class InsertRootElementFilterInputStream extends FilterInputStream {
9693
}
9794
}
9895

96+
private boolean isResultsTag(PushbackInputStream pin) throws IOException {
97+
// Try extending
98+
ByteArrayOutputStream atResultsChars = new ByteArrayOutputStream();
99+
int ech;
100+
boolean resultsTag = true;
101+
for (byte b : resultsTagBytes) {
102+
ech = this.in.read();
103+
atResultsChars.write(ech);
104+
if (ech != b) {
105+
// Extension failed. Put the bytes back on and search again.
106+
pin.unread(atResultsChars.toByteArray());
107+
resultsTag = false;
108+
break;
109+
}
110+
}
111+
return resultsTag;
112+
}
113+
99114
@Override
100115
public int read(byte[] buffer, int offset, int length) throws IOException {
101-
int result = in.read(buffer, offset, length);
116+
// first we read from the buffer before the first results xml tag
117+
int result = 0;
118+
int availableFromBuffer = beforeResultsBuffer.available();
119+
if (offset < availableFromBuffer) {
120+
result = beforeResultsBuffer.read(buffer, offset, length);
121+
if (length <= result) {
122+
return result;
123+
}
124+
}
125+
126+
// then we read from the original input stream
127+
result += in.read(buffer, offset+result, length-result);
102128
if (result == -1 && wrotePrefix) {
103129
// No more bytes to read from in, and we have written '<doc>' earlier in the stream
104130
return suffix.read(buffer, offset, length);

0 commit comments

Comments
 (0)