@@ -105,16 +105,37 @@ public void flush() {
105
105
String json =
106
106
SERVICE_VERSION_ADAPTER .toJson (
107
107
new ServiceVersion (serviceName , env , version , "JAVA" , scopesToSerialize ));
108
- if (json .length () > maxPayloadSize ) {
109
- LOGGER .debug (
110
- "Upload split is required for {} scopes: {}/{}" ,
111
- scopesToSerialize .size (),
112
- json .length (),
113
- maxPayloadSize );
114
- splitAndSend (scopesToSerialize );
108
+ updateStats (scopesToSerialize , json );
109
+ doUpload (scopesToSerialize , json );
110
+ }
111
+
112
+ private void doUpload (List <Scope > scopesToSerialize , String json ) {
113
+ byte [] jsonBytes = json .getBytes (StandardCharsets .UTF_8 );
114
+ byte [] payload = null ;
115
+ if (isCompressed ) {
116
+ payload = compressPayload (jsonBytes );
117
+ }
118
+ if (payload == null ) {
119
+ if (json .length () > maxPayloadSize ) {
120
+ LOGGER .warn ("Payload is too big: {}/{}" , json .length (), maxPayloadSize );
121
+ splitAndSend (scopesToSerialize );
122
+ return ;
123
+ }
124
+ symbolUploader .uploadAsMultipart (
125
+ "" ,
126
+ event ,
127
+ new BatchUploader .MultiPartContent (jsonBytes , "file" , "file.json" , APPLICATION_JSON ));
115
128
} else {
116
- LOGGER .debug ("Sending {} jar scopes size={}" , scopesToSerialize .size (), json .length ());
117
- doUpload (scopesToSerialize , json );
129
+ if (payload .length > maxPayloadSize ) {
130
+ LOGGER .warn ("Compressed payload is too big: {}/{}" , payload .length , maxPayloadSize );
131
+ splitAndSend (scopesToSerialize );
132
+ return ;
133
+ }
134
+ LOGGER .debug ("Sending {} jar scopes size={}" , scopesToSerialize .size (), payload .length );
135
+ symbolUploader .uploadAsMultipart (
136
+ "" ,
137
+ event ,
138
+ new BatchUploader .MultiPartContent (payload , "file" , "file.gz" , APPLICATION_GZIP ));
118
139
}
119
140
}
120
141
@@ -146,16 +167,6 @@ private void splitAndSend(List<Scope> scopesToSerialize) {
146
167
SERVICE_VERSION_ADAPTER .toJson (
147
168
new ServiceVersion (
148
169
serviceName , env , version , "JAVA" , Collections .singletonList (scope )));
149
- if (json .length () > maxPayloadSize ) {
150
- // this jar scope is still too big, split it by classes
151
- LOGGER .debug (
152
- "Upload split is required for jar scope {}: {}/{}" ,
153
- scope .getName (),
154
- json .length (),
155
- maxPayloadSize );
156
- splitAndSend (Collections .singletonList (scope ));
157
- continue ;
158
- }
159
170
LOGGER .debug ("Sending {} jar scope size={}" , scope .getName (), json .length ());
160
171
doUpload (Collections .singletonList (scope ), json );
161
172
}
@@ -168,22 +179,10 @@ private void splitAndSend(List<Scope> scopesToSerialize) {
168
179
String jsonFirstHalf =
169
180
SERVICE_VERSION_ADAPTER .toJson (
170
181
new ServiceVersion (serviceName , env , version , "JAVA" , firstHalf ));
171
- if (jsonFirstHalf .length () > maxPayloadSize ) {
172
- LOGGER .warn (
173
- "Cannot split jar scope list in 2, first half is too big: {}" ,
174
- jsonFirstHalf .length ());
175
- return ;
176
- }
177
182
doUpload (firstHalf , jsonFirstHalf );
178
183
String jsonSecondHalf =
179
184
SERVICE_VERSION_ADAPTER .toJson (
180
185
new ServiceVersion (serviceName , env , version , "JAVA" , secondHalf ));
181
- if (jsonSecondHalf .length () > maxPayloadSize ) {
182
- LOGGER .warn (
183
- "Cannot split jar scope list in 2, second half is too big: {}" ,
184
- jsonSecondHalf .length ());
185
- return ;
186
- }
187
186
doUpload (secondHalf , jsonSecondHalf );
188
187
}
189
188
} else {
@@ -213,31 +212,6 @@ private void splitAndSend(List<Scope> scopesToSerialize) {
213
212
}
214
213
}
215
214
216
- private void doUpload (List <Scope > scopes , String json ) {
217
- updateStats (scopes , json );
218
- byte [] jsonBytes = json .getBytes (StandardCharsets .UTF_8 );
219
- byte [] payload = null ;
220
- if (isCompressed ) {
221
- payload = compressPayload (jsonBytes );
222
- }
223
- if (payload == null ) {
224
- if (jsonBytes .length > maxPayloadSize ) {
225
- LOGGER .warn ("Compressed payload is too big: {}/{}" , payload .length , maxPayloadSize );
226
- splitAndSend (scopes );
227
- return ;
228
- }
229
- symbolUploader .uploadAsMultipart (
230
- "" ,
231
- event ,
232
- new BatchUploader .MultiPartContent (jsonBytes , "file" , "file.json" , APPLICATION_JSON ));
233
- } else {
234
- symbolUploader .uploadAsMultipart (
235
- "" ,
236
- event ,
237
- new BatchUploader .MultiPartContent (payload , "file" , "file.gz" , APPLICATION_GZIP ));
238
- }
239
- }
240
-
241
215
private static Scope createJarScope (String jarName , List <Scope > classScopes ) {
242
216
return Scope .builder (ScopeType .JAR , jarName , 0 , 0 ).name (jarName ).scopes (classScopes ).build ();
243
217
}
0 commit comments