+ /**
+ * Method to write a string to a file
+ * @Param filePath the file's path
+ * @Param content the data to be writen
+ * @throws IOException if error happends
+ */
+ private static void writeFileByFileWriter(String filePath, String content) throws IOException {
+ File file = new File(filePath);
+ synchronized (file) {
+ try (FileWriter fw = new FileWriter(filePath)) {
+ fw.write(content);
+ } catch (final IOException exp) {
+ LOGGER.error("Failed to write File by File Writer ", exp);
+ }
+ }
+ }
+ /**
+ * Method to write the downloaded distribution artifact to local file system with specified dir.
+ *
+ * @param artifact the notification artifact
+ * @param resultArtifact the download result artifact
+ * @return the local path of written file
+ * @throws ArtifactDownloadException if error occurs while writing the artifact
+ */
+ private Path writeArtifactToDir(final IArtifactInfo artifact,
+ final IDistributionClientDownloadResult resultArtifact, Path path) throws ArtifactDownloadException {
+ try {
+ final byte[] payloadBytes = resultArtifact.getArtifactPayload();
+ //final File tempArtifactFile = File.createTempFile(artifact.getArtifactName(), ".csar");
+ File tempArtifactFile = new File(path.toString() + "/" + artifact.getArtifactName());
+ try (FileOutputStream fileOutputStream = new FileOutputStream(tempArtifactFile)) {
+ fileOutputStream.write(payloadBytes, 0, payloadBytes.length);
+ return tempArtifactFile.toPath();
+ }
+ } catch (final Exception exp) {
+ final String message = "Failed to write artifact to local repository";
+ LOGGER.error(message, exp);
+ throw new ArtifactDownloadException(message, exp);
+ }
+ }
+