拷贝文件，本方法会将输入输出流关闭。
435313
public static void copyFile(InputStream _inputStream, String newFile) throws IOException {
        try (InputStream inputStream = _inputStream;
             FileOutputStream outputStream = new FileOutputStream(newFile)) {
            int length = 2097152;
            byte[] buffer = new byte[length];
            while (true) {
                int read = inputStream.read(buffer);
                if (read == -1) {
                    outputStream.flush();
                    break;
                } else {
                    outputStream.write(buffer, 0, read);
                }
            }
        }
    }
818562
public void train(Reader reader, String modelFile) throws Exception {
		/**
		 * 分类模型
		 */
		//建立字典管理器
		AlphabetFactory af = AlphabetFactory.buildFactory();

		//使用n元特征
		Pipe ngrampp = new NGram(new int[] {1,2});
		//将字符特征转换成字典索引
		Pipe indexpp = new StringArray2IndexArray(af);
		//将目标值对应的索引号作为类别
		Pipe targetpp = new Target2Label(af.DefaultLabelAlphabet());		

		//建立pipe组合
		SeriesPipes pp = new SeriesPipes(new Pipe[]{ngrampp,targetpp,indexpp});
		
		SeriesPipes  pp2 = new SeriesPipes(new Pipe[]{prePipe, ngrampp,targetpp,indexpp});
		
		InstanceSet instset = new InstanceSet(pp2,af);



		//读入数据，并进行数据处理
		instset.loadThruStagePipes(reader);

		/**
		 * 建立分类器
		 */		
		OnlineTrainer trainer = new OnlineTrainer(af,100);
		trainer.c = 0.01f;
		pclassifier = trainer.train(instset);
		pp.removeTargetPipe();
		pclassifier.setPipe(pp);
		af.setStopIncrement(true);

		//将分类器保存到模型文件
		pclassifier.saveTo(modelFile);	
	}
402473
public static function init_file_direct($filename, $filesize, $path, $is_full = false, $fsencoding = '') {
        if ($is_full) {
            $dest = $path;
        }
        else {
            $dest = WEB_ROOT . $path;
        }

        $dest = self::conv_to($dest, $fsencoding);
        self::mkdir(dirname($dest));

        $dh = fopen($dest, 'w+');
        if ($dh === false) {
            throw new Exception('文件建立失败');
        }
        if (!ftruncate($dh, $filesize)) {
            unlink($dest);
            throw new Exception('文件建立失败');
        }
        fclose($dh);

        $cfg_path = $dest . '.ucfg';
        $dh = fopen($cfg_path, 'w+');
        if ($dh === false) {
            throw new Exception('文件建立失败');
        }
        fclose($dh);

        return $path;
    }
817205
function watchOnFile(file, callback) {
  let lastIndex = 0
  let timer

  function read() {
    const stat = fs.statSync(file)

    if (stat.size !== lastIndex) {
      const fd = fs.openSync(file, 'r')
      const buffer = Buffer.alloc(stat.size - lastIndex)

      try {
        fs.readSync(fd, buffer, lastIndex, stat.size - lastIndex)
        const content = buffer.toString('utf8')
        lastIndex = stat.size

        callback(content)
      } catch (error) {
        // 从头读起
        lastIndex = 0
      }
    }

    timer = setTimeout(read, 200)
  }

  read()
  return function() {
    clearTimeout(timer)
  }
}
364977
private void readTail() throws IOException {
		final long len = this.randomAccessFile.length();

		if (initReadLine > 0) {
			long start = this.randomAccessFile.getFilePointer();
			long nextEnd = len - 1;
			this.randomAccessFile.seek(nextEnd);
			int c;
			int currentLine = 0;
			while (nextEnd > start) {
				// 满
				if (currentLine > initReadLine) {
					break;
				}
				c = this.randomAccessFile.read();
				if (c == CharUtil.LF || c == CharUtil.CR) {
					FileUtil.readLine(this.randomAccessFile, this.charset, this.lineHandler);
					currentLine++;
					nextEnd--;
				}
				nextEnd--;
				this.randomAccessFile.seek(nextEnd);
				if (nextEnd == 0) {
					// 当文件指针退至文件开始处，输出第一行
					FileUtil.readLine(this.randomAccessFile, this.charset, this.lineHandler);
					break;
				}
			}
		}

		// 将指针置于末尾
		try {
			this.randomAccessFile.seek(len);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
1246319
function(filesArr) {
		// 读取package.json，将里面内容生成头信息
		var data = fs.readFileSync('./package.json', 'utf8');
		var packageObj = JSON.parse( data );

		var headerStr = '/** \r\n';
			headerStr += ' * ' + packageObj.name + ' v' + packageObj.version + '\r\n';
			headerStr += ' * ' + packageObj.description + '\r\n';
			headerStr += ' * author : ' + packageObj.author + '\r\n';
			headerStr += ' * homepage : ' + packageObj.homepage + '\r\n';
			headerStr += ' * bugs : ' + packageObj.bugs.url + '\r\n';
			headerStr += ' **/ \r\n';


		for (var i = 0; i < filesArr.length; i++){
			var filePath = filesArr[i]
			var data = fs.readFileSync(filePath, 'utf8');
			data = headerStr  + data;
			fs.writeFileSync(filePath, data);
		}
	}
313924
private static void packagingAction(Method[] methods, Object handlerBean) {
        if (ArrayUtils.isEmpty(methods)) {
            return;
        }
        // 参数唯一，且为public
        Predicate<Method> commonFilter = method -> Modifier.isPublic(method.getModifiers())
                && method.getParameterCount() == 1
                && Objects.isNull(handlerBean) == Modifier.isStatic(method.getModifiers());

        Arrays.stream(methods).filter(commonFilter).forEach(method -> ConverterContext.setAction(method, handlerBean));
    }
1258079
function processFile(file, encoding) {
    var fileContent = file.contents.toString(encoding),
        matches = fileContent.match(reg$$Global),
        expression,
        tempRegResults,
        name,
        value,
        replaceStr;

    if(null === matches) {
        return file;
    }
    for(var i = 0, len = matches.length; i < len; i ++) {
        expression = matches[i];
        tempRegResults = expression.match(reg$$);
        name = tempRegResults[1];
        value = tempRegResults[2];

        replaceStr = (resolvers[name] || loop)(file, valueProcess(name, value));
        //替换表达式的值为应该替换的那一部分
        fileContent = fileContent.replace(expression, replaceStr.replace("$", "$$$$"));
    }

    file.contents = new Buffer(fileContent);
    return file;
}
1169814
function rudePackager(ret, pack, settings, opt) {
  var files = ret.src;
  var sources = _.toArray(files);

  // 生成映射表，方便快速查找！
  var idmapping = ret.idmapping = {};
  var urlmapping = ret.urlmapping = {};
  Object.keys(files).forEach(function(subpath) {
    var file = files[subpath];
    idmapping[file.id] = file;
    if (file.release) {
      urlmapping[file.getUrl()] = file;
    }
  });

  var includeList = [];
  // 如果有设置需要额外的模块加入到 resouceMap 当中
  if (settings.include) {
    var patterns = settings.include;
    if (!Array.isArray(patterns)) {
      patterns = [patterns];
    }

    
    patterns.forEach(function(pattern, index) {
      var exclude = typeof pattern === 'string' && pattern.substring(0, 1) === '!';

      if (exclude) {
        pattern = pattern.substring(1);

        // 如果第一个规则就是排除用法，都没有获取结果就排除，这是不合理的用法。
        // 不过为了保证程序的正确性，在排除之前，通过 `**` 先把所有文件获取到。
        // 至于性能问题，请用户使用时规避。
        index === 0 && (includeList = find('**'));
      }

      var mathes = find(pattern);
      includeList = _[exclude ? 'difference' : 'union'](includeList, mathes);
    });
  }

  Object.keys(files).forEach(function(subpath) {
    var file = files[subpath];

    compile(file);
  });

  function find(reg) {
    if (files[reg]) {
      return [files[reg]];
    } else if (reg === '**') {
      // do nothing
    } else if (typeof reg === 'string') {
      reg = _.glob(reg);
    }

    return sources.filter(function(file) {
      reg.lastIndex = 0;
      return (reg === '**' || reg.test(file.subpath));
    });
  }

  function compile(file) {
    var processor = rudePackager.lang[file.loaderLang] ||
      rudePackager.lang[settings.processor[file.ext]] ||
      rudePackager.lang.html;

    // 非 htmlLike 或者 没有处理器，或者已经处理过了，则跳过。
    if (file.release === false ||
        !file.isHtmlLike ||
        file.loaderLang === false ||
        file.loaderLang === null ||
        !processor ||
        file._resource) {
      return;
    }

    // 可以让 processor 调用。
    processor._compile = compile;

    // 修改之前先，先备份。
    file._rudeBackup = file.getContent();

    var resource = createResource(ret, file, settings);
    file._resource = resource;
    processor.init && processor.init(file, resource, settings);

    processor.beforePack && processor.beforePack(file, resource, settings, includeList);

    if (settings.allInOne) {
      allInOnePack(file, resource, ret, settings.allInOne === true ? {} : settings.allInOne);
    }

    processor.before && processor.before(file, resource, settings);
    processor(file, resource, settings);
    processor.after && processor.after(file, resource, settings);

    file.useCache = false; // 让其缓存失效，watch 的时候，下次需要重新发布过去。
    ret.pkg[file.subpath] = file;
  }
}
957505
def write_outfile(method_name, file)
      schema = @load_schema.call(self)
      context = @load_context.call(self)
      result = schema.public_send(method_name, only: @only, except: @except, context: context)
      dir = File.dirname(file)
      FileUtils.mkdir_p(dir)
      File.write(file, result)
    end
170205
function executeFile(src, { context, babelOptions } = {}) {
    let filename = resolvePath(context)(src);

    // 不存在文件
    if (!filename) {
        throw new Error(`Error: ENOENT: no such file, open '${src}'`);
    }

    // 解析【json】
    if (filename.endsWith('.json')) {
        return require(filename);
    }

    // 解析对象
    return execute(
        fs.readFileSync(filename, 'utf-8'), { filename, babelOptions }
    );
}
605732
function setZip(context, config, _stream, pathname) {
  const ext = path.extname(pathname).toLowerCase()
  if (ZIPFILE.indexOf(ext) === -1) {
    return _stream
  }
  const acceptEncoding = context.acceptEncoding
  // 如果acceptEncoding不为数组，就返回值
  if (!Array.isArray(acceptEncoding)) {
    return _stream
  }
  let zip = config.zip
  // 获取客户端支持的encoding
  let encoding = getEncoding(zip, acceptEncoding)
  // 设置压缩格式，并返回压缩后的响应正文
  switch (encoding) {
    case 'gzip':
      context.set({
        'Content-Encoding': 'gzip',
        'Transfer-Encoding': 'chunked'
      })
      return _stream.pipe(zlib.createGzip())
      break
    case 'deflate':
      context.set({
        'Content-Encoding': 'deflate',
        'Transfer-Encoding': 'chunked'
      })
      return _stream.pipe(zlib.createDeflate())
      break
    default:
      return _stream
      break
  }
  /**
   * 获取客户端和服务器支持的压缩格式
   * 并选择一种压缩格式
   * @param  {Mixed} _zip             config zip配置
   * @param  {Array} _acceptEncoding  客户端支持的压缩格式
   * @return {String}
   */
  function getEncoding(_zip, _acceptEncoding) {
    if (!_zip) {
      return false
    }
    if (_zip == true) {
      _zip = ENCODING
    }
    if ('string' === typeof _zip) {
      _zip = [_zip]
    }
    if (!Array.isArray(_zip)) {
      return false
    }
    for (let i = 0, length = _acceptEncoding.length; i < length; i++) {
      for (let j = 0; j < _zip.length; j++) {
        if (_zip[j] === _acceptEncoding[i]) {
          return _acceptEncoding[i].toLocaleLowerCase()
        }
      }
    }
  }
}
794901
function Queue() {
    
            /**
             * 统计文件数。
             * * `numOfQueue` 队列中的文件数。
             * * `numOfSuccess` 上传成功的文件数
             * * `numOfCancel` 被移除的文件数
             * * `numOfProgress` 正在上传中的文件数
             * * `numOfUploadFailed` 上传错误的文件数。
             * * `numOfInvalid` 无效的文件数。
             * @property {Object} stats
             */
            this.stats = {
                numOfQueue: 0,
                numOfSuccess: 0,
                numOfCancel: 0,
                numOfProgress: 0,
                numOfUploadFailed: 0,
                numOfInvalid: 0
            };
    
            // 上传队列，仅包括等待上传的文件
            this._queue = [];
    
            // 存储所有文件
            this._map = {};
        }
1175344
function renderFile(data, hsc, mime) {
		hsc = hsc || httpStatusCode;
		mime = mime || MimeType.OCTET_STREAM;
		res.writeHead(hsc, {
			"Content-Type": mime,
			"Set-Cookie": resCookie.print()
		});
		// 后面的还不会，还要再研究
		end();
	}
728240
function runFile(src, context) {

    // 格式作路径
    src = path.cwd(src);

    // 返回运行结果
    return runCode(fs.readFileSync(src, 'utf8'), {
        __dirname: path.dirname(src),
        __filename: src,
        ...context
    });
}
275128
function walk(dir, doneFn) {
    fs.readdir(dir, (err, list) => {
      if (err) return doneFn(err);

      list.forEach((file) => {
        // img图片不部署，使用七牛云单独存储
        if (path.basename(dir) === options.outputDir && file === 'img') return;

        file = path.resolve(dir, file);

        fs.stat(file, (eror, stats) => {
          if (eror) return doneFn(err);

          const isFile = stats.isFile(); // 是文件
          const isDir = stats.isDirectory(); // 是文件夹

          if (isFile) {
            return doneFn(null, file);
          }
          if (isDir) {
            walk(file, doneFn); // 递归，如果是文件夹，就继续遍历该文件夹下面的文件
          }
        });
      });
    });
  }
732499
private List<FileData> doFileExtract(RowBatch rowBatch) {
        List<FileData> fileDatas = new ArrayList<FileData>();
        // 处理数据
        Pipeline pipeline = getPipeline(rowBatch.getIdentity().getPipelineId());
        List<EventData> eventDatas = rowBatch.getDatas();
        for (EventData eventData : eventDatas) {
            if (eventData.getEventType().isDdl()) {
                continue;
            }

            List<DataMediaPair> dataMediaPairs = ConfigHelper.findDataMediaPairByMediaId(pipeline,
                                                                                         eventData.getTableId());
            if (dataMediaPairs == null) {
                throw new ExtractException("ERROR ## the dataMediaId = " + eventData.getTableId()
                                           + " dataMediaPair is null,please check");
            }

            for (DataMediaPair dataMediaPair : dataMediaPairs) {
                if (dataMediaPair.getResolverData() == null
                    || dataMediaPair.getResolverData().getExtensionDataType() == null
                    || (dataMediaPair.getResolverData().getExtensionDataType().isClazz() && StringUtils.isBlank(dataMediaPair.getResolverData().getClazzPath()))
                    || (dataMediaPair.getResolverData().getExtensionDataType().isSource() && StringUtils.isBlank(dataMediaPair.getResolverData().getSourceText()))) {
                    continue;
                }

                FileResolver fileResolver = null;

                if (dataMediaPair.getResolverData() != null) {
                    fileResolver = extensionFactory.getExtension(FileResolver.class, dataMediaPair.getResolverData());
                } else {
                    continue;
                }

                if (fileResolver == null) {
                    throw new ExtractException("ERROR ## the dataMediaId = " + eventData.getTableId()
                                               + " the fileResolver className  = "
                                               + dataMediaPair.getResolverData().getClazzPath()
                                               + " is null ,please check the class");
                }

                if (fileResolver instanceof RemoteDirectoryFetcherAware) {
                    RemoteDirectoryFetcherAware remoteDirectoryFetcherAware = (RemoteDirectoryFetcherAware) fileResolver;
                    remoteDirectoryFetcherAware.setRemoteDirectoryFetcher(arandaRemoteDirectoryFetcher);
                }

                List<FileData> singleRowFileDatas = getSingleRowFileInfos(dataMediaPair.getId(), fileResolver,
                                                                          eventData);
                // 做一下去重处理
                for (FileData data : singleRowFileDatas) {
                    if (!fileDatas.contains(data)) {
                        fileDatas.add(data);
                    }
                }
            }
        }

        // 判断是否需要进行图片重复同步检查
        if (pipeline.getParameters().getFileDetect()) {
            doFileDetectCollector(pipeline, fileDatas);
        }
        return fileDatas;
    }