-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a util class for commodities we lost from java 11
- Loading branch information
Showing
3 changed files
with
56 additions
and
14 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
14 changes: 2 additions & 12 deletions
14
src/main/java/io/camunda/operate/CamundaOperateConstants.java
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,30 +1,20 @@ | ||
package io.camunda.operate; | ||
|
||
import java.util.AbstractMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import io.camunda.operate.dto.FlownodeInstance; | ||
import io.camunda.operate.dto.Incident; | ||
import io.camunda.operate.dto.ProcessDefinition; | ||
import io.camunda.operate.dto.ProcessInstance; | ||
import io.camunda.operate.dto.Variable; | ||
import io.camunda.operate.util.Java8Utils; | ||
|
||
public class CamundaOperateConstants { | ||
|
||
public static Map<Class<?>, String> OBJECT_APIS = toMap(ProcessDefinition.class, "/v1/process-definitions", | ||
public static Map<Class<?>, String> OBJECT_APIS = Java8Utils.toMap(ProcessDefinition.class, "/v1/process-definitions", | ||
ProcessInstance.class, "/v1/process-instances", | ||
FlownodeInstance.class, "/v1/flownode-instances", | ||
Incident.class, "/v1/incidents", | ||
Variable.class, "/v1/variables"); | ||
|
||
private static Map<Class<?>, String> toMap(Object... array) { | ||
AbstractMap.SimpleEntry<Class<?>, String>[] entryArray = new AbstractMap.SimpleEntry[array.length/2]; | ||
for(int i=0;i<entryArray.length;i++) { | ||
entryArray[i]= new AbstractMap.SimpleEntry<Class<?>, String>((Class<?>)array[i*2], (String) array[i*2+1]); | ||
} | ||
return Stream.of(entryArray) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.camunda.operate.util; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.AbstractMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class Java8Utils { | ||
|
||
private Java8Utils() { | ||
|
||
} | ||
|
||
public static byte[] readAllBytes(InputStream inputStream) throws IOException { | ||
final int bufLen = 4 * 0x400; // 4KB | ||
byte[] buf = new byte[bufLen]; | ||
int readLen; | ||
IOException exception = null; | ||
|
||
try { | ||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { | ||
while ((readLen = inputStream.read(buf, 0, bufLen)) != -1) | ||
outputStream.write(buf, 0, readLen); | ||
|
||
return outputStream.toByteArray(); | ||
} | ||
} catch (IOException e) { | ||
exception = e; | ||
throw e; | ||
} finally { | ||
if (exception == null) inputStream.close(); | ||
else try { | ||
inputStream.close(); | ||
} catch (IOException e) { | ||
exception.addSuppressed(e); | ||
} | ||
} | ||
} | ||
|
||
public static Map<Class<?>, String> toMap(Object... array) { | ||
AbstractMap.SimpleEntry<Class<?>, String>[] entryArray = new AbstractMap.SimpleEntry[array.length/2]; | ||
for(int i=0;i<entryArray.length;i++) { | ||
entryArray[i]= new AbstractMap.SimpleEntry<Class<?>, String>((Class<?>)array[i*2], (String) array[i*2+1]); | ||
} | ||
return Stream.of(entryArray) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
} |