use of java.util.zip.DataFormatException in project geode by apache.
the class MiscellaneousCommands method netstat.
@CliCommand(value = CliStrings.NETSTAT, help = CliStrings.NETSTAT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public // TODO : Verify the auto-completion for multiple values.
Result netstat(@CliOption(key = CliStrings.NETSTAT__MEMBER, mandatory = false, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.NETSTAT__MEMBER__HELP) String[] members, @CliOption(key = CliStrings.NETSTAT__GROUP, mandatory = false, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.NETSTAT__GROUP__HELP) String group, @CliOption(key = CliStrings.NETSTAT__FILE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.NETSTAT__FILE__HELP) String saveAs, @CliOption(key = CliStrings.NETSTAT__WITHLSOF, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.NETSTAT__WITHLSOF__HELP) boolean withlsof) {
Result result = null;
Map<String, DistributedMember> hostMemberMap = new HashMap<String, DistributedMember>();
Map<String, List<String>> hostMemberListMap = new HashMap<String, List<String>>();
try {
if (members != null && members.length > 0 && group != null) {
throw new IllegalArgumentException(CliStrings.NETSTAT__MSG__ONLY_ONE_OF_MEMBER_OR_GROUP_SHOULD_BE_SPECIFIED);
}
StringBuilder resultInfo = new StringBuilder();
// Execute for remote members whose id or name matches
InternalDistributedSystem system = InternalDistributedSystem.getConnectedInstance();
if (members != null) {
Set<String> notFoundMembers = new HashSet<String>();
for (String memberIdOrName : members) {
Set<DistributedMember> membersToExecuteOn = CliUtil.getAllMembers(system);
boolean memberFound = false;
for (DistributedMember distributedMember : membersToExecuteOn) {
String memberName = distributedMember.getName();
String memberId = distributedMember.getId();
if (memberName.equals(memberIdOrName) || memberId.equals(memberIdOrName)) {
buildMaps(hostMemberMap, hostMemberListMap, memberIdOrName, distributedMember);
memberFound = true;
break;
}
}
if (!memberFound) {
notFoundMembers.add(memberIdOrName);
}
}
// if there are not found members, it's probably unknown member or member has departed
if (!notFoundMembers.isEmpty()) {
throw new IllegalArgumentException(CliStrings.format(CliStrings.NETSTAT__MSG__COULD_NOT_FIND_MEMBERS_0, new Object[] { CliUtil.collectionToString(notFoundMembers, -1) }));
}
} else {
Set<DistributedMember> membersToExecuteOn = null;
if (group != null) {
membersToExecuteOn = system.getGroupMembers(group);
} else {
// consider all members
membersToExecuteOn = CliUtil.getAllMembers(system);
}
for (DistributedMember distributedMember : membersToExecuteOn) {
String memberName = distributedMember.getName();
String memberId = distributedMember.getId();
String memberIdOrName = memberName != null && !memberName.isEmpty() ? memberName : memberId;
buildMaps(hostMemberMap, hostMemberListMap, memberIdOrName, distributedMember);
}
}
String lineSeparatorToUse = null;
lineSeparatorToUse = CommandExecutionContext.getShellLineSeparator();
if (lineSeparatorToUse == null) {
lineSeparatorToUse = GfshParser.LINE_SEPARATOR;
}
NetstatFunctionArgument nfa = new NetstatFunctionArgument(lineSeparatorToUse, withlsof);
if (!hostMemberMap.isEmpty()) {
Set<DistributedMember> membersToExecuteOn = new HashSet<DistributedMember>(hostMemberMap.values());
ResultCollector<?, ?> netstatResult = CliUtil.executeFunction(NetstatFunction.INSTANCE, nfa, membersToExecuteOn);
List<?> resultList = (List<?>) netstatResult.getResult();
for (int i = 0; i < resultList.size(); i++) {
NetstatFunctionResult netstatFunctionResult = (NetstatFunctionResult) resultList.get(i);
DeflaterInflaterData deflaterInflaterData = netstatFunctionResult.getCompressedBytes();
try {
String remoteHost = netstatFunctionResult.getHost();
List<String> membersList = hostMemberListMap.get(remoteHost);
resultInfo.append(MessageFormat.format(netstatFunctionResult.getHeaderInfo(), CliUtil.collectionToString(membersList, 120)));
DeflaterInflaterData uncompressedBytes = CliUtil.uncompressBytes(deflaterInflaterData.getData(), deflaterInflaterData.getDataLength());
resultInfo.append(new String(uncompressedBytes.getData()));
} catch (DataFormatException e) {
resultInfo.append("Error in some data. Reason : " + e.getMessage());
}
}
}
InfoResultData resultData = ResultBuilder.createInfoResultData();
if (saveAs != null && !saveAs.isEmpty()) {
String saveToFile = saveAs;
if (!saveAs.endsWith(NETSTAT_FILE_REQUIRED_EXTENSION)) {
saveToFile = saveAs + NETSTAT_FILE_REQUIRED_EXTENSION;
}
resultData.addAsFile(saveToFile, resultInfo.toString(), CliStrings.NETSTAT__MSG__SAVED_OUTPUT_IN_0, // Note: substitution for {0} will
false);
// happen on client side.
} else {
resultData.addLine(resultInfo.toString());
}
result = ResultBuilder.buildResult(resultData);
} catch (IllegalArgumentException e) {
LogWrapper.getInstance().info(CliStrings.format(CliStrings.NETSTAT__MSG__ERROR_OCCURRED_WHILE_EXECUTING_NETSTAT_ON_0, new Object[] { Arrays.toString(members) }));
result = ResultBuilder.createUserErrorResult(e.getMessage());
} catch (RuntimeException e) {
LogWrapper.getInstance().info(CliStrings.format(CliStrings.NETSTAT__MSG__ERROR_OCCURRED_WHILE_EXECUTING_NETSTAT_ON_0, new Object[] { Arrays.toString(members) }), e);
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.NETSTAT__MSG__ERROR_OCCURRED_WHILE_EXECUTING_NETSTAT_ON_0, new Object[] { Arrays.toString(members) }));
} finally {
hostMemberMap.clear();
hostMemberListMap.clear();
}
return result;
}
use of java.util.zip.DataFormatException in project voltdb by VoltDB.
the class AbstractHistogramLogReader method nextIntervalHistogram.
private EncodableHistogram nextIntervalHistogram(final Double rangeStartTimeSec, final Double rangeEndTimeSec, boolean absolute) {
while (scanner.hasNextLine()) {
try {
if (scanner.hasNext("\\#.*")) {
// comment line
if (scanner.hasNext("#\\[StartTime:")) {
scanner.next("#\\[StartTime:");
if (scanner.hasNextDouble()) {
// start time represented as seconds since epoch
setStartTimeSec(scanner.nextDouble());
}
}
scanner.nextLine();
continue;
}
if (scanner.hasNext("\"StartTimestamp\".*")) {
// Legend line
scanner.nextLine();
continue;
}
// Decode: startTimestamp, intervalLength, maxTime, histogramPayload
// Timestamp start is expect to be in seconds
final double offsetStartTimeStampSec = scanner.nextDouble();
final double absoluteStartTimeStampSec = getStartTimeSec() + offsetStartTimeStampSec;
// Timestamp length is expect to be in seconds
final double intervalLengthSec = scanner.nextDouble();
final double offsetEndTimeStampSec = offsetStartTimeStampSec + intervalLengthSec;
final double absoluteEndTimeStampSec = getStartTimeSec() + offsetEndTimeStampSec;
final double startTimeStampToCheckRangeOn = absolute ? absoluteStartTimeStampSec : offsetStartTimeStampSec;
if (startTimeStampToCheckRangeOn < rangeStartTimeSec) {
scanner.nextLine();
continue;
}
if (startTimeStampToCheckRangeOn > rangeEndTimeSec) {
return null;
}
// Skip maxTime field, as max time can be deduced from the histogram.
scanner.nextDouble();
final String compressedPayloadString = scanner.next();
final ByteBuffer buffer = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(compressedPayloadString));
EncodableHistogram histogram = Histogram.decodeFromCompressedByteBuffer(buffer, 0);
histogram.setStartTimeStamp((long) (absoluteStartTimeStampSec * 1000.0));
histogram.setEndTimeStamp((long) (absoluteEndTimeStampSec * 1000.0));
return histogram;
} catch (java.util.NoSuchElementException ex) {
return null;
} catch (DataFormatException ex) {
return null;
}
}
return null;
}
use of java.util.zip.DataFormatException in project bitsquare by bitsquare.
the class Utils method decompress.
private static byte[] decompress(byte[] compressedData, int length) {
Inflater inflater = new Inflater();
inflater.setInput(compressedData, 0, length);
ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
byte[] buf = new byte[8192];
while (!inflater.finished()) {
try {
int count = inflater.inflate(buf);
bos.write(buf, 0, count);
} catch (DataFormatException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return bos.toByteArray();
}
use of java.util.zip.DataFormatException in project cas by apereo.
the class CompressionUtils method inflate.
/**
* Inflate the given byte array by {@link #INFLATED_ARRAY_LENGTH}.
*
* @param bytes the bytes
* @return the array as a string with {@code UTF-8} encoding
*/
public static String inflate(final byte[] bytes) {
final Inflater inflater = new Inflater(true);
final byte[] xmlMessageBytes = new byte[INFLATED_ARRAY_LENGTH];
final byte[] extendedBytes = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, extendedBytes, 0, bytes.length);
extendedBytes[bytes.length] = 0;
inflater.setInput(extendedBytes);
try {
final int resultLength = inflater.inflate(xmlMessageBytes);
inflater.end();
if (!inflater.finished()) {
throw new IllegalArgumentException("buffer not large enough.");
}
inflater.end();
return new String(xmlMessageBytes, 0, resultLength, StandardCharsets.UTF_8);
} catch (final DataFormatException e) {
return null;
}
}
use of java.util.zip.DataFormatException in project vcell by virtualcell.
the class MediaMethods method makeMediaInformation.
/**
* This method was created in VisualAge.
* @return TrackAtom
* @param track Track
*/
private static final MediaInformation makeMediaInformation(MediaTrack track) throws DataFormatException {
SampleTableDescription stsd = new SampleTableDescription(track.getSampleDescriptionEntries());
TimeToSample stts = new TimeToSample(track.getSampleDurations());
SyncSample stss = new SyncSample(track.getKeyFrames());
SampleToChunk stsc = new SampleToChunk(track.getChunkIDs());
SampleSize stsz = new SampleSize(track.getSampleSizes());
ChunkOffset stco = new ChunkOffset(track.getChunkOffsets());
SampleTable stbl = new SampleTable(stsd, stts, stss, stsc, stsz, stco);
DataReferenceEntry[] entries = new DataReferenceEntry[track.getDataReferences().length];
for (int i = 0; i < track.getDataReferences().length; i++) entries[i] = new DataReferenceEntry(track.getDataReferences()[i], track.getDataReferenceTypes()[i]);
DataReference dref = new DataReference(entries);
DataInformation dinf = new DataInformation(dref);
HandlerReference dhlr = new HandlerReference("dhlr", AtomConstants.COMPONENT_SUBTYPE_FILE_ALIAS);
if (track.getMediaType().equals(AtomConstants.MEDIA_TYPE_VIDEO)) {
VideoMediaInformationHeader vmhd = new VideoMediaInformationHeader();
return new VideoMediaInformation(vmhd, dhlr, dinf, stbl);
} else if (track.getMediaType().equals(AtomConstants.MEDIA_TYPE_OBJECT) || track.getMediaType().equals(AtomConstants.MEDIA_TYPE_QTVR)) {
BaseMediaInfo gmin = new BaseMediaInfo();
BaseMediaHeader gmhd = new BaseMediaHeader(gmin);
return new BaseMediaInformation(gmhd, dhlr, dinf, stbl);
} else {
throw new DataFormatException("Unknown media type");
}
}
Aggregations