This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from zalando/ARUHA-473-check-size-of-events
Aruha 473 check size of events
- testPlugin
- r20170426rc1
- r2017_08_10-aruha-1026-v2
- r2017_08_10-aruha-1026-v1
- r3.3.10-2019-12-05
- r3.3.10-2019-12-04
- r3.3.10-2019-12-03
- r3.3.9-2019-10-31
- r3.3.8-2019-10-23
- r3.3.7-2019-10-21
- r3.3.6-2019-10-17
- r3.2.4-2019-08-01
- r3.2.3-2019-10-01
- r3.2.3-2019-08-20
- r3.2.3-2019-07-18
- r3.2.2-2019-08-09
- r3.2.2-2019-07-01
- r3.2.1-2019-07-18
- r3.2.0-2019-08-07
- r3.2.0-2019-06-27
- r3.1.14-2019-06-24
- r3.1.13-2019-06-13
- r3.1.12-2019-05-15
- r3.1.11-2019-05-07
- r3.1.10-2019-04-29
- r3.1.9.2019-03-25
- r3.1.9-2019-04-24
- r3.1.8-2019-03-06
- r3.1.7-2019-03-05
- r3.1.5-2019-02-27
- r3.1.4-2019-02-27
- r3.1.2-2019-02-26
- r3.1.1-2019-02-25
- r3.1.0-2019-02-19
- r3.0.12-2019-02-12
- r3.0.11-2019-02-06
- r3.0.10-2019-01-29
- r3.0.10-2019-01-28
- r3.0.9-2019-01-24
- r3.0.9-2019-01-14
- r3.0.9-2019-01-07
- r3.0.8-2019-01-02
- r3.0.7-2018-12-04
- r3.0.6-2018-12-03
- r3.0.4-2018-11-16
- r3.0.3-2018-11-13
- r3.0.2-2018-11-06
- r3.0.2-2018-11-02
- r3.0.2-2018-10-31
- r3.0.2-2018-10-29
- r3.0.1-2018-10-18
- r3.0.0-2018-10-18
- r2.9.1-2018-10-11
- r2.9.0-2018-10-04
- r2.8.7-2018-09-04
- r2.8.6-2018-08-27
- r2.8.5-2018-08-22
- r2.8.5-2018-08-09
- r2.8.4-2018-08-02
- r2.8.3-2018-08-01
- r2.8.2-2018-07-31
- r2.8.1-2018-07-23
- r2.8.0-2018-07-16
- r2.7.8-2018-07-02
- r2.7.7-2018-06-26
- r2.7.6-2018-06-21
- r2.7.5-2018-06-20
- r2.7.4-2018-06-13
- r2.7.3-2018-06-11
- r2.7.3-2018-06-07
- r2.7.2-2018-05-30
- r2.7.1-2018-05-28
- r2.7.0-2018-05-25
- r2.6.7-2018-05-15
- r2.6.6-2018-05-08
- r2.6.5-2018-05-03
- r2.6.4-2018-04-26
- r2.6.3-2018-04-12
- r2.6.3-2018-04-10
- r2.6.2-2018-04-05
- r2.6.1-2018-04-03
- r2.6.0-2018-03-26
- r2.5.9-2018-03-06
- r2.5.8-2017-02-22
- r2.5.7-2018-02-15
- r2.5.6-2018-02-07
- r2.5.5-2018-01-24
- r2.5.4-2018-01-18
- r2.5.3-2018-01-15
- r2.5.2-2018-01-08
- r2.5.1-2018-01-03
- r2.5.0-2017-12-27
- r2.4.2-2017-12-21
- r2.4.1-2017-12-19
- r2.3.5-2017-12-15
- r2.3.4-2017-12-14
- r2.3.3-2017-12-12
- r2.3.2-2017-12-05
- r2.3.1-2017-11-29
- r2.3.0-2017-11-16
- r2.2.9-2017-11-14
- r2.2.9-2017-11-02
- r2.2.8-2017-11-01
- r2.2.7-2017-10-25
- r2.2.6-2017-10-17
- r2.2.4-2017-10-13
- r2.2.3-2017-10-13
- r2.2.2-2017-09-28
- r2.2.1-2017-09-26
- r2.2.0-2017-08-29
- r2.1.1-2017-08-22
- r2.1.0-2017-08-21
- r2.0.1-2017-08-11
- r2.0.0-2017-08-09
- r2.0.0-1-2017-08-10
- r.1.1.3-2017-08-03
- r1.1.1-2017-08-01
- r1.1.1-2017-07-26
- r1.1.0-2017-07-25
- r1.0.1-2017-07-14
- r1.0.0-2017-07-12
- cursor-ops-rc6
- cursor-ops-rc4
- cursor-ops-rc3
- cursor-ops-rc2
- cursor-ops-rc1
- aruha-1136-v3
- aruha-1136-v2
- aruha-1136-v1
- aruha-1079-v1
- aruha-1077-v1
- aruha-952-v3
- aruha-952-v2
- aruha-952-v1
- aruha-929-930-v1
- aruha-823-v1
- aruha-809-v1
- aruha-778-v6
- aruha-778-v5
- aruha-778-v4
- aruha-778-v3
- aruha-778-v2
- aruha1083v3
- aruha1083v2
- aruha1083v1
- aruha1015v9-jetty-500-threads
- aruha1015v8-jetty-no-lz4
- aruha1015v7-base-branch-with-lz4
- aruha1015v6-jetty
- aruha1015v5-jetty
- aruha1015v4
- aruha1015v3
- aruha1015v2
- aruha1015v1
- aruha870-v4
- aruha870-v3
- aruha870-v2
- aruha870-v1
- aruha870-rc1
- aruha860rc1
- aruha858und838rc1
- aruha858rc1
- aruha840rc1
- aruha840liveRC1
- aruha778-rc1
- aruha677rc3
- aruha677rc1
- aruha668-short-offset-retention
- arhua-952-v4
- R20170613rc1
- R20170405rc1
- R20170314rc1
- R20170308issue596rc1
- R20170307issue586rc1
- R20170307issue585rc1
- R20170302aruha592
- R20170302aruha592rc1
- R20170207hotfixquotaRC1
- R2017_12_13-aruha-1389-v1
- R2017_08_02_aruha-953-v1
- R2017_07_04
- R2017_06_29
- R2017_06_28
- R2017_06_27
- R2017_06_23_aruha-759-v1
- R2017_06_15
- R2017_06_08
- R2017_05_29
- R2017_05_18
- R2017_05_18_aruha-778-v1
- R2017_05_17
- R2017_05_15
- R2017_05_10_aruha-681-v1
- R2017_05_09
- R2017_05_03
- R2017_04_24
- R2017_04_24_v2
- R2017_04_20
- R2017_04_19_aruha-732-v1
- R2017_04_13
- R2017_04_12
- R2017_04_12_aruha713-v2
- R2017_04_10
- R2017_04_05_aruha-681-v1
- R2017_03_27_aruha-681-v1
- R2017_03_07
- R2017_03_06
- R2017_03_03
- R2017_02_23
- R2017_02_21
- R2017_02_13
- R2017_02_08
- R2017_02_06
- R2017_02_03_aruha-633-v1
- R2017_02_02_aruha-523_v2
- R2017_02_01_aruha-523
- R2017_01_23
- 2017_04_07-aruha-713-v1
- 1.0.0
Showing
17 changed files
with
590 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,82 @@ | ||
package org.zalando.nakadi.domain; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BatchFactory { | ||
|
||
public static List<BatchItem> from(final JSONArray events) { | ||
final List<BatchItem> batch = new ArrayList<>(events.length()); | ||
for (int i = 0; i < events.length(); i++) { | ||
batch.add(new BatchItem(events.getJSONObject(i))); | ||
public static List<BatchItem> from(final String events) { | ||
final List<BatchItem> batch = new ArrayList<>(); | ||
StringBuilder sb = new StringBuilder(); | ||
int brackets = 0; | ||
boolean insideQuote = false; | ||
boolean escaped = false; | ||
int start = 0; | ||
final int length = events.length(); | ||
int end = length - 1; | ||
|
||
while (isEmptyCharacter(events.charAt(start)) && start < end) { | ||
start++; | ||
} | ||
while (isEmptyCharacter(events.charAt(end)) && end > start) { | ||
end--; | ||
} | ||
if (!(events.charAt(start) == '[')) { | ||
throw new JSONException(String.format("Unexpected character %s in position %d, expected '['", | ||
events.charAt(start), start)); | ||
} | ||
start++; | ||
if (!(events.charAt(end) == ']')) { | ||
throw new JSONException(String.format("Unexpected character %s in position %d, expected ']'", | ||
events.charAt(end), end)); | ||
} | ||
|
||
for (int i = start; i < end; i++) { | ||
if (!escaped && events.charAt(i) == '"') { | ||
if (insideQuote) { | ||
insideQuote = false; | ||
} else { | ||
insideQuote = true; | ||
} | ||
} | ||
if (escaped) { | ||
sb.append(events.charAt(i)); | ||
escaped = false; | ||
} else if (!escaped && events.charAt(i) == '\\') { | ||
sb.append(events.charAt(i)); | ||
escaped = true; | ||
} else if (insideQuote) { | ||
sb.append(events.charAt(i)); | ||
} else { | ||
if (events.charAt(i) == '{') { | ||
brackets++; | ||
} | ||
if (events.charAt(i) == '}') { | ||
brackets--; | ||
} | ||
if (!((brackets == 0) && ((events.charAt(i) == ',') | ||
|| isEmptyCharacter(events.charAt(i))))) { | ||
sb.append(events.charAt(i)); | ||
} | ||
if (brackets == 0 && !isEmptyCharacter(events.charAt(i))) { | ||
if (sb.length() > 0) { | ||
batch.add(new BatchItem(sb.toString())); | ||
} | ||
sb = new StringBuilder(); | ||
} | ||
} | ||
} | ||
|
||
if (sb.length() != 0) { | ||
batch.add(new BatchItem(sb.toString())); | ||
} | ||
|
||
return batch; | ||
} | ||
|
||
private static boolean isEmptyCharacter(final char c) { | ||
return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.