use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class DataPointVO method copy.
/* ############################## */
@Override
public DataPointVO copy() {
try {
DataPointVO copy = (DataPointVO) super.clone();
// is all of this necessary after we made a clone?
copy.setChartColour(chartColour);
copy.setRollup(rollup);
copy.setChartRenderer(chartRenderer);
copy.setDataSourceId(dataSourceId);
copy.setDataSourceName(dataSourceName);
copy.setDataSourceTypeName(dataSourceTypeName);
copy.setDataSourceXid(dataSourceXid);
copy.setDefaultCacheSize(defaultCacheSize);
copy.setDeviceName(deviceName);
copy.setDiscardExtremeValues(discardExtremeValues);
copy.setDiscardHighLimit(discardHighLimit);
copy.setDiscardLowLimit(discardLowLimit);
copy.setEnabled(enabled);
copy.setEventDetectors(eventDetectors);
copy.setIntegralUnit(integralUnit);
copy.setIntervalLoggingPeriod(intervalLoggingPeriod);
copy.setIntervalLoggingPeriodType(intervalLoggingPeriodType);
copy.setIntervalLoggingType(intervalLoggingType);
copy.setLoggingType(loggingType);
copy.setName(name);
copy.setPlotType(plotType);
copy.setSimplifyType(simplifyType);
copy.setSimplifyTolerance(simplifyTolerance);
copy.setSimplifyTarget(simplifyTarget);
copy.setPointFolderId(pointFolderId);
copy.setTextRenderer(textRenderer);
copy.setPointLocator(pointLocator);
copy.setPurgeOverride(purgeOverride);
copy.setPurgePeriod(purgePeriod);
copy.setPurgeType(purgeType);
copy.setRenderedUnit(renderedUnit);
copy.setSettable(settable);
copy.setTolerance(tolerance);
copy.setUnit(unit);
copy.setUseIntegralUnit(useIntegralUnit);
copy.setUseRenderedUnit(useRenderedUnit);
copy.setXid(xid);
copy.setOverrideIntervalLoggingSamples(overrideIntervalLoggingSamples);
copy.setIntervalLoggingSampleWindowSize(intervalLoggingSampleWindowSize);
copy.setReadPermission(readPermission);
copy.setSetPermission(setPermission);
copy.setTemplateId(templateId);
copy.setPreventSetExtremeValues(preventSetExtremeValues);
copy.setSetExtremeHighLimit(setExtremeHighLimit);
copy.setSetExtremeLowLimit(setExtremeLowLimit);
copy.setTags(this.tags);
return copy;
} catch (CloneNotSupportedException e) {
throw new ShouldNeverHappenException(e);
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class JsonSerializableUtility method digestsDiffer.
private boolean digestsDiffer(Object fromValue, Object toValue) throws IOException, JsonException {
try (DigestOutputStream dos = new DigestOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
// no-op, just digesting
}
}, MessageDigest.getInstance("MD5"));
OutputStreamWriter toStreamWriter = new OutputStreamWriter(dos);
OutputStreamWriter fromStreamWriter = new OutputStreamWriter(dos)) {
JsonWriter fromWriter = new JsonWriter(Common.JSON_CONTEXT, fromStreamWriter);
// We need fresh writers to avoid miscellaneous commas or whatnot
JsonWriter toWriter = new JsonWriter(Common.JSON_CONTEXT, toStreamWriter);
fromWriter.writeObject(fromValue);
fromWriter.flush();
byte[] fromDigest = dos.getMessageDigest().digest();
fromDigest = Arrays.copyOf(fromDigest, fromDigest.length);
toWriter.writeObject(toValue);
toWriter.flush();
byte[] toDigest = dos.getMessageDigest().digest();
return !Arrays.equals(fromDigest, toDigest);
} catch (NoSuchAlgorithmException e) {
// Required to implement MD5, really shouldn't happen
throw new ShouldNeverHappenException(e);
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class ImageUtils method encodeImage.
public static byte[] encodeImage(BufferedImage image, BaseImageFormat encodingFormat) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
if (encodingFormat.supportsCompression()) {
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(encodingFormat.getType());
ImageWriter writer = iter.next();
if (writer == null)
throw new ShouldNeverHappenException("No writers for image format type " + encodingFormat.getType());
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(encodingFormat.getCompressionQuality());
ImageOutputStream ios = new MemoryCacheImageOutputStream(out);
writer.setOutput(ios);
IIOImage iioImage = new IIOImage(image, null, null);
writer.write(null, iioImage, iwp);
ios.close();
} else
ImageIO.write(image, encodingFormat.getType(), out);
return out.toByteArray();
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class SerializationHelper method writeObjectToArray.
public static byte[] writeObjectToArray(Object o) throws ShouldNeverHappenException {
if (o == null)
return null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(o);
return baos.toByteArray();
} catch (IOException e) {
throw new ShouldNeverHappenException(e);
}
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class ResourceBundleLoader method findResource.
@Override
protected URL findResource(String name) {
URL url = super.findResource(name);
if (url != null)
return url;
File file = new File(directory, name);
if (file.exists()) {
try {
return file.toURI().toURL();
} catch (MalformedURLException e) {
throw new ShouldNeverHappenException(e);
}
}
return null;
}
Aggregations