Search in sources :

Example 61 with ShouldNeverHappenException

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);
    }
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 62 with ShouldNeverHappenException

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);
    }
}
Also used : DigestOutputStream(java.security.DigestOutputStream) OutputStream(java.io.OutputStream) DigestOutputStream(java.security.DigestOutputStream) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) JsonWriter(com.serotonin.json.JsonWriter)

Example 63 with ShouldNeverHappenException

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();
}
Also used : MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) ImageWriter(javax.imageio.ImageWriter) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageWriteParam(javax.imageio.ImageWriteParam) ImageOutputStream(javax.imageio.stream.ImageOutputStream) MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) IIOImage(javax.imageio.IIOImage)

Example 64 with ShouldNeverHappenException

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);
    }
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 65 with ShouldNeverHappenException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) File(java.io.File) URL(java.net.URL)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)83 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)10 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)9 SQLException (java.sql.SQLException)9 ParseException (java.text.ParseException)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 FileNotFoundException (java.io.FileNotFoundException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ResultSet (java.sql.ResultSet)5 Statement (java.sql.Statement)5 JsonException (com.serotonin.json.JsonException)4 JsonWriter (com.serotonin.json.JsonWriter)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)4 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)4 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringWriter (java.io.StringWriter)4 HashMap (java.util.HashMap)4