Java Code Examples for org.activiti.engine.impl.util.IoUtil#closeSilently()

The following examples show how to use org.activiti.engine.impl.util.IoUtil#closeSilently() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessDiagramCanvas.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * <p/>
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiException("ProcessDiagramGenerator already closed");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiException("Error while generating process image", e);
    } finally {
        IoUtil.closeSilently(out);
    }
    return new ByteArrayInputStream(out.toByteArray());
}
 
Example 2
Source File: ProcessDiagramCanvas.java    From maven-framework-project with MIT License 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * 
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
  if (closed) {
    throw new ActivitiException("ProcessDiagramGenerator already closed");
  }

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  try {
    // Try to remove white space
    minX = (minX <= 5) ? 5 : minX;
    minY = (minY <= 5) ? 5 : minY;
    BufferedImage imageToSerialize = processDiagram;
    if (minX >= 0 && minY >= 0) {
      imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
    }
    ImageIO.write(imageToSerialize, imageType, out);
  } catch (IOException e) {
    throw new ActivitiException("Error while generating process image", e);
  } finally {
    IoUtil.closeSilently(out);
  }
  return new ByteArrayInputStream(out.toByteArray());
}
 
Example 3
Source File: ProcessDiagramCanvas.java    From maven-framework-project with MIT License 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * 
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
  if (closed) {
    throw new ActivitiException("ProcessDiagramGenerator already closed");
  }

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  try {
    // Try to remove white space
    minX = (minX <= 5) ? 5 : minX;
    minY = (minY <= 5) ? 5 : minY;
    BufferedImage imageToSerialize = processDiagram;
    if (minX >= 0 && minY >= 0) {
      imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
    }
    ImageIO.write(imageToSerialize, imageType, out);
  } catch (IOException e) {
    throw new ActivitiException("Error while generating process image", e);
  } finally {
    IoUtil.closeSilently(out);
  }
  return new ByteArrayInputStream(out.toByteArray());
}
 
Example 4
Source File: ProcessDiagramCanvas.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * <p/>
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiException("ProcessDiagramGenerator already closed");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiException("Error while generating process image", e);
    } finally {
        IoUtil.closeSilently(out);
    }
    return new ByteArrayInputStream(out.toByteArray());
}
 
Example 5
Source File: ProcessDiagramCanvas.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * <p/>
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiException("ProcessDiagramGenerator already closed");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiException("Error while generating process image", e);
    } finally {
        IoUtil.closeSilently(out);
    }
    return new ByteArrayInputStream(out.toByteArray());
}
 
Example 6
Source File: ProcessDiagramCanvas.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * <p/>
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiException("ProcessDiagramGenerator already closed");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiException("Error while generating process image", e);
    } finally {
        IoUtil.closeSilently(out);
    }
    return new ByteArrayInputStream(out.toByteArray());
}
 
Example 7
Source File: ProcessDiagramCanvas.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * <p/>
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiException("ProcessDiagramGenerator already closed");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiException("Error while generating process image", e);
    } finally {
        IoUtil.closeSilently(out);
    }
    return new ByteArrayInputStream(out.toByteArray());
}
 
Example 8
Source File: ProcessDiagramCanvas.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * <p/>
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiException("ProcessDiagramGenerator already closed");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiException("Error while generating process image", e);
    } finally {
        IoUtil.closeSilently(out);
    }
    return new ByteArrayInputStream(out.toByteArray());
}
 
Example 9
Source File: ProcessDiagramCanvas.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * <p/>
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiException("ProcessDiagramGenerator already closed");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiException("Error while generating process image", e);
    } finally {
        IoUtil.closeSilently(out);
    }
    return new ByteArrayInputStream(out.toByteArray());
}
 
Example 10
Source File: SerializableType.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public byte[] serialize(Object value, ValueFields valueFields) {
  if (value == null) {
    return null;
  }
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ObjectOutputStream oos = null;
  try {
    oos = createObjectOutputStream(baos);
    oos.writeObject(value);
  } catch (Exception e) {
    throw new ActivitiException("Couldn't serialize value '"+value+"' in variable '"+valueFields.getName()+"'", e);
  } finally {
    IoUtil.closeSilently(oos);
  }
  return baos.toByteArray();
}
 
Example 11
Source File: ProcessDiagramCanvas.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an image of what currently is drawn on the canvas.
 * <p/>
 * Throws an {@link ActivitiException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiException("ProcessDiagramGenerator already closed");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiException("Error while generating process image", e);
    } finally {
        IoUtil.closeSilently(out);
    }
    return new ByteArrayInputStream(out.toByteArray());
}
 
Example 12
Source File: SerializableType.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public byte[] serialize(Object value, ValueFields valueFields) {
    if (value == null) {
        return null;
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = null;
    try {
        oos = createObjectOutputStream(baos);
        oos.writeObject(value);
    } catch (Exception e) {
        throw new ActivitiException("Couldn't serialize value '" + value + "' in variable '" + valueFields.getName() + "'", e);
    } finally {
        IoUtil.closeSilently(oos);
    }
    return baos.toByteArray();
}
 
Example 13
Source File: DbSqlSession.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void executeSchemaResource(String operation, String component, String resourceName, boolean isOptional) {
  InputStream inputStream = null;
  try {
    inputStream = ReflectUtil.getResourceAsStream(resourceName);
    if (inputStream == null) {
      if (isOptional) {
        log.info("no schema resource {} for {}", resourceName, operation);
      } else {
        throw new ActivitiException("resource '" + resourceName + "' is not available");
      }
    } else {
      executeSchemaResource(operation, component, resourceName, inputStream);
    }

  } finally {
    IoUtil.closeSilently(inputStream);
  }
}
 
Example 14
Source File: ProcessEngines.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static ProcessEngine buildProcessEngine(URL resource) {
    InputStream inputStream = null;
    try {
        inputStream = resource.openStream();
        ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(inputStream);
        return processEngineConfiguration.buildProcessEngine();

    } catch (IOException e) {
        throw new ActivitiIllegalArgumentException("couldn't open resource stream: " + e.getMessage(), e);
    } finally {
        IoUtil.closeSilently(inputStream);
    }
}
 
Example 15
Source File: SerializableType.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public Object deserialize(byte[] bytes, ValueFields valueFields) {
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    try {
        ObjectInputStream ois = createObjectInputStream(bais);
        Object deserializedObject = ois.readObject();

        return deserializedObject;
    } catch (Exception e) {
        throw new ActivitiException("Couldn't deserialize object in variable '" + valueFields.getName() + "'", e);
    } finally {
        IoUtil.closeSilently(bais);
    }
}
 
Example 16
Source File: ProcessEngines.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private static ProcessEngine buildProcessEngine(URL resource) {
  InputStream inputStream = null;
  try {
    inputStream = resource.openStream();
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(inputStream);
    return processEngineConfiguration.buildProcessEngine();

  } catch (IOException e) {
    throw new ActivitiIllegalArgumentException("couldn't open resource stream: " + e.getMessage(), e);
  } finally {
    IoUtil.closeSilently(inputStream);
  }
}
 
Example 17
Source File: SerializableType.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Object deserialize(byte[] bytes, ValueFields valueFields) {
  ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
  try {
    ObjectInputStream ois = createObjectInputStream(bais);
    Object deserializedObject = ois.readObject();

    return deserializedObject;
  } catch (Exception e) {
    throw new ActivitiException("Couldn't deserialize object in variable '"+valueFields.getName()+"'", e);
  } finally {
    IoUtil.closeSilently(bais);
  }
}