/* (non-Javadoc)
@see com.popbill.api.TaxinvoiceService#attachFile(java.lang.String, com.popbill.api.taxinvoice.MgtKeyType, java.lang.String, java.lang.String, java.io.InputStream)
427367
@Override
    public Response attachFile(String CorpNum, MgtKeyType KeyType,
                               String MgtKey, String DisplayName, InputStream FileData)
            throws PopbillException {
        return attachFile(CorpNum, KeyType, MgtKey, DisplayName, FileData, null);
    }
627281
public void addAttachment(final String name, final String type,
                              final String fileExtension, final InputStream stream) {
        writeAttachment(prepareAttachment(name, type, fileExtension), stream);
    }
1252981
public void addAttachment(final DataHandler handler, final String filename)
		throws MessagingException
	{
		final BodyPart part = new MimeBodyPart();
		part.setFileName(filename);
		part.setDataHandler(handler);
		addAttachment(part);
	}
187373
String copyFile(
            final ExecutionContext executionContext,
            final File file,
            final InputStream input,
            final String content,
            final INodeEntry node,
            String destination
    ) throws FileCopierException
    {
        final String pluginname = getProvider().getName();
        final Map<String, Map<String, String>> localDataContext = createScriptDataContext(
            executionContext.getFramework(),
            executionContext.getFrameworkProject(),
            executionContext.getDataContext());
        //add node context data
        localDataContext.put("node", DataContextUtils.nodeData(node));

        Description pluginDesc = getDescription();
        //load config.* property values in from project or framework scope
        final Map<String, Map<String, String>> finalDataContext;
        try {
            finalDataContext = loadConfigData(executionContext, loadInstanceDataFromNodeAttributes(node, pluginDesc), localDataContext, pluginDesc,
                                              ServiceNameConstants.FileCopier
            );
        } catch (ConfigurationException e) {
            throw new FileCopierException("[" + pluginname + "]: "+e.getMessage(),
                    StepFailureReason.ConfigurationFailure, e);
        }

        final File srcFile =
                null != file ?
                        file :
                        BaseFileCopier.writeTempFile(executionContext, null, input, content);

        String destFilePath = destination;
        if (null == destFilePath) {

            String identity = null!=executionContext.getDataContext() && null!=executionContext.getDataContext().get("job")?
                              executionContext.getDataContext().get("job").get("execid"):null;
            destFilePath = BaseFileCopier.generateRemoteFilepathForNode(
                    node,
                    executionContext.getFramework().getFrameworkProjectMgr().getFrameworkProject(executionContext.getFrameworkProject()),
                    executionContext.getFramework(),
                    (null != file ? file.getName() : "dispatch-script"),
                    null,
                    identity
            );
        }
        //put file in a directory
        if (null != destFilePath && destFilePath.endsWith("/")) {
            destFilePath += srcFile.getName();
        }
        //add some more data context values to allow templatized script-copy attribute
        final HashMap<String, String> scptexec = new HashMap<>();
        //set up the data context to include the local temp file
        scptexec.put("file", srcFile.getAbsolutePath());
        scptexec.put("destination", null != destFilePath ? destFilePath : "");
        finalDataContext.put("file-copy", scptexec);
        Map<String, Map<String, String>> fileCopyContext =
                DataContextUtils.addContext(
                        "file-copy",
                        scptexec,
                        null
                );

        final ExecArgList execArgList = createScriptArgsList(fileCopyContext);
        final String localNodeOsFamily=getFramework().createFrameworkNode().getOsFamily();

        executionContext.getExecutionListener().log(3,
                                                    "[" +
                                                    getProvider().getName() +
                                                    "] executing: " +
                                                    execArgList.asFlatStringList()
        );

        final ByteArrayOutputStream captureSysOut = new ByteArrayOutputStream();
        try {
            final int result = getScriptExecHelper().runLocalCommand(
                    localNodeOsFamily,
                    execArgList,
                    finalDataContext,
                    null,
                    captureSysOut,
                    System.err
            );
            executionContext.getExecutionListener().log(3, "[" + pluginname + "]: result code: " + result);
            if(result!=0){
                throw new FileCopierException("[" + pluginname + "]: external script failed with exit code: " + result,
                                              NodeStepFailureReason.NonZeroResultCode);
            }
        } catch (IOException e) {
            throw new FileCopierException("[" + pluginname + "] " + e.getMessage(), StepFailureReason.IOFailure);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new FileCopierException("[" + pluginname + "] " + e.getMessage(), StepFailureReason.Interrupted);
        }finally {
            if(null == file) {
                if (!ScriptfileUtils.releaseTempFile(srcFile)) {
                    executionContext.getExecutionListener().log(
                            Constants.WARN_LEVEL,
                            "Unable to remove local temp file: " + srcFile.getAbsolutePath()
                    );
                }
            }
        }


        //load string of output from outputstream
        final String output = captureSysOut.toString();
        if (null == output || output.length() < 1) {
            if (null != destFilePath) {
                return destFilePath;
            }
            throw new FileCopierException("[" + pluginname + "]: No output from external script",
                                          ScriptPluginFailureReason.ScriptPluginFileCopierOutputMissing
            );
        }
        //TODO: require any specific format for the data?
        //look for first line of output
        final String[] split1 = output.split("(\\r?\\n)");
        if (split1.length < 1) {
            if (null != destFilePath) {
                return destFilePath;
            }
            throw new FileCopierException("[" + pluginname + "]: No output from external script",
                                          ScriptPluginFailureReason.ScriptPluginFileCopierOutputMissing);
        }
        final String remotefilepath = split1[0];

        executionContext.getExecutionListener().log(3, "[" + pluginname + "]: result filepath: " + remotefilepath);

        return remotefilepath;
    }
418708
function _attachStreamMethod(qb) {
  /**
   * Create the stream function for a pass through to the datastax driver,
   * all callbacks are defaulted to lodash#noop if not declared.
   *
   * @param `{Object} options` optional argument passed to datastax driver upon query execution
   * @param `{Object} cbs` =>
   * {
     *  readable: function() {},
     *  end: function() {},
     *  error: function(err) {}
     * }
   * @returns {Client|exports|module.exports}
   */
  qb.stream = function (options, cbs) {

    var _options = _.isObject(cbs) ? options : {}
      , _cbs = _.isObject(cbs) ? cbs : options
      , onReadable = _cbs.readable || _.noop
      , onEnd = _cbs.end || _.noop
      , onError = _cbs.error || _.noop;

    if (cassandra !== null && cassandra.connected) {
      var cql = qb.cql();
      cassandra.stream(cql, qb.bindings(), _options)
        .on("readable", onReadable)
        .on("end", onEnd)
        .on("error", onError);
    }
    else {
      console.error("Cassandra client is not initialized.");
      onError(new Error("Cassandra client is not initialized."));
    }

    // maintain chain
    return qb;
  };
}
551216
public MessageBuilder addAttachmentAsSpoiler(InputStream stream, String fileName) {
        delegate.addAttachment(stream, "SPOILER_" + fileName);
        return this;
    }
816198
public static Attachment fromTextInputStream( InputStream inputStream, MediaType mediaType ) throws IOException {
        return fromText( CharStreams.toString( new InputStreamReader( inputStream, mediaType.getCharset() ) ), mediaType );
    }
78511
@Override
    public TaxinvoiceInfo[] getInfos(String CorpNum, MgtKeyType KeyType,
                                     String[] MgtKeyList) throws PopbillException {
        if (KeyType == null)
            throw new PopbillException(-99999999, "관리번호형태가 입력되지 않았습니다.");
        if (MgtKeyList == null || MgtKeyList.length == 0)
            throw new PopbillException(-99999999, "관리번호 목록이 입력되지 않았습니다.");

        String PostData = toJsonString(MgtKeyList);

        return httppost("/Taxinvoice/" + KeyType.name(), CorpNum, PostData,
                null, TaxinvoiceInfo[].class);
    }
315401
@Override
	public String sendFAX(String corpNum, String sendNum, Receiver[] receivers,
			File file, Date reserveDT) throws PopbillException {

		return requestFax(corpNum, sendNum, null, receivers, new File[]{file}, 
				reserveDT, null, null, null, null);
	}
820174
public function attachFile($file, $fileName = null)
    {
        if (gettype($file) == 'resource') {
            $this->file = ['fileName' => $fileName, 'fileContent' => $file];
        } else {
            $this->file = ['fileName' => $fileName, 'fileContent' => fopen($file, 'r')];
        }
    }
1226174
private static void doCopyFile(final File srcFile, final File destFile, final boolean preserveFileDate) {
        if (destFile.exists()) {
            throw new IllegalArgumentException("The destination file already existed: " + destFile.getAbsolutePath());
        }

        FileInputStream fis = null;
        FileOutputStream fos = null;
        FileChannel input = null;
        FileChannel output = null;

        try {
            fis = new FileInputStream(srcFile);
            fos = new FileOutputStream(destFile);
            input = fis.getChannel();
            output = fos.getChannel();

            long size = input.size();
            long pos = 0;
            long count = 0;

            while (pos < size) {
                count = ((size - pos) > FILE_COPY_BUFFER_SIZE) ? FILE_COPY_BUFFER_SIZE : (size - pos);
                pos += output.transferFrom(input, pos, count);
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        } finally {
            close(output);
            close(fos);
            close(input);
            close(fis);
        }

        if (srcFile.length() != destFile.length()) {
            deleteAllIfExists(destFile);
            throw new UncheckedIOException(new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'"));
        }

        if (preserveFileDate) {
            destFile.setLastModified(srcFile.lastModified());
        }
    }
533941
def save_file(self, data, dfile):
        
        self.enforce_type(self.jobject, "weka.core.converters.FileSourcedConverter")
        if not javabridge.is_instance_of(dfile, "Ljava/io/File;"):
            dfile = javabridge.make_instance(
                "Ljava/io/File;", "(Ljava/lang/String;)V", javabridge.get_env().new_string_utf(str(dfile)))
        javabridge.call(self.jobject, "setFile", "(Ljava/io/File;)V", dfile)
        javabridge.call(self.jobject, "setInstances", "(Lweka/core/Instances;)V", data.jobject)
        javabridge.call(self.jobject, "writeBatch", "()V")
336799
public void setAttachment(String type, String url, Boolean is_reusable)
    {
        this.message_attachment.put("type", type);
        this.message_attachment.put("url", url);
        this.message_attachment.put("is_reusable", String.valueOf(is_reusable));
    }
330122
@Override
    public Response delete(String CorpNum, MgtKeyType KeyType, String MgtKey,
                           String UserID) throws PopbillException {
        if (KeyType == null)
            throw new PopbillException(-99999999, "관리번호형태가 입력되지 않았습니다.");
        if (MgtKey == null || MgtKey.isEmpty())
            throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");

        return httppost("/Taxinvoice/" + KeyType.name() + "/" + MgtKey,
                CorpNum, null, UserID, "DELETE", Response.class);
    }
371563
@Override
    public Response update(String CorpNum, MgtKeyType KeyType, String MgtKey,
                           Taxinvoice taxinvoice) throws PopbillException {
        return update(CorpNum, KeyType, MgtKey, taxinvoice, null);

    }
944309
public static Attachment fromBinaryFile( File file, MediaType mediaType ) throws IOException {
        FileInputStream stream = new FileInputStream( file );
        try {
            return fromBinaryInputStream( stream, mediaType );
        } finally {
            ResourceUtil.close( stream );
        }
    }
1020121
public ClassificationModel attachClassification(GraphRewrite event, ClassificationModel classificationModel, FileModel fileModel)
    {
        if (fileModel instanceof DuplicateArchiveModel)
        {
            fileModel = ((DuplicateArchiveModel) fileModel).getCanonicalArchive();
        }

        if (!isClassificationLinkedToFileModel(event, classificationModel, fileModel))
        {
            classificationModel.addFileModel(fileModel);
            if (fileModel instanceof SourceFileModel)
                ((SourceFileModel) fileModel).setGenerateSourceReport(true);
        }
        ClassificationServiceCache.cacheClassificationFileModel(event, classificationModel, fileModel, true);

        return classificationModel;
    }