训练数据，得到每个词对的出现次数
@param inputFile 训练数据文件
@throws Exception
774094
public void build(String... inputFile) throws Exception {
		System.out.println("read file ..."); 
				
		
		for(String file:inputFile){
			LinkedList<Integer> n1gramList = new LinkedList<Integer>();
			for(int i=0;i<n;i++){
				n1gramList.add(-1);
			}
			Scanner scanner = new Scanner(new FileInputStream(file), "utf-8");
			while(scanner.hasNext()) { 
				String s = scanner.next();
				int idx = wordDict.lookupIndex(s);
				n1gramList.add(idx);
				n1gramList.remove();
				assert n1gramList.size()==n;
				
				String[] grams = getNgram(n1gramList);
				String n1gram = grams[0];
				String ngram = grams[1];
				
				int n1gramidx = n1gramDict.lookupIndex(n1gram);
				if(n1gramidx==n1gramCount.size())
					n1gramCount.add(1);
				else if(n1gramidx>n1gramCount.size()){
					throw new Exception();
				}
				else{
					int count = n1gramCount.get(n1gramidx);
					n1gramCount.set(n1gramidx, count+1);
				}

				
				int ngramidx = ngramDict.lookupIndex(ngram);
				
				if(ngramidx==prob.size())
					prob.add(1);
				else if(ngramidx>prob.size()){
					throw new Exception();
				}
				else{
					float count = prob.get(ngramidx);
					prob.set(ngramidx, count+1);
				}
				
				
				
				if(index.contains(ngramidx))
					assert(index.get(ngramidx) == n1gramidx);
				else
					index.put(ngramidx, n1gramidx);

			}
			scanner.close();
		}
		
		ngramDict.setStopIncrement(true);
		n1gramDict.setStopIncrement(true);
		wordDict.setStopIncrement(true);
		System.out.println("词表大小" + wordDict.size());

	}
951776
public static void copyStream( File inputFile, File outputFile ) throws IOException {
		InputStream is = new FileInputStream( inputFile );
		try {
			copyStream( is, outputFile );
		} finally {
			is.close();
		}
	}
1125540
public void process(File file) throws Exception
   {
      openLogFile();

      int blockIndex = 0;
      int length = (int) file.length();
      m_buffer = new byte[length];
      FileInputStream is = new FileInputStream(file);
      try
      {
         int bytesRead = is.read(m_buffer);
         if (bytesRead != length)
         {
            throw new RuntimeException("Read count different");
         }
      }
      finally
      {
         is.close();
      }

      List<Integer> blocks = new ArrayList<Integer>();
      for (int index = 64; index < m_buffer.length - 11; index++)
      {
         if (matchPattern(PARENT_BLOCK_PATTERNS, index))
         {
            blocks.add(Integer.valueOf(index));
         }
      }

      int startIndex = 0;
      for (int endIndex : blocks)
      {
         int blockLength = endIndex - startIndex;
         readBlock(blockIndex, startIndex, blockLength);
         startIndex = endIndex;
         ++blockIndex;
      }

      int blockLength = m_buffer.length - startIndex;
      readBlock(blockIndex, startIndex, blockLength);

      closeLogFile();
   }
739234
public static void main(String[] args) throws Exception {
		args = new String[2];
		args[0] = "./tmp/CoNLL2009-ST-Chinese-train.txt";
		args[1] = "./tmp/modelConll.gz";
		Options opt = new Options();

		opt.addOption("h", false, "Print help for this application");
		opt.addOption("iter", true, "iterative num, default 50");
		opt.addOption("c", true, "parameters 1, default 1");

		BasicParser parser = new BasicParser();
		CommandLine cl;
		try {
			cl = parser.parse(opt, args);
		} catch (Exception e) {
			System.err.println("Parameters format error");
			return;
		}
		
		if (args.length == 0 || cl.hasOption('h')) {
			HelpFormatter f = new HelpFormatter();
			f.printHelp(
					"Tagger:\n"
							+ "ParserTrainer [option] train_file model_file;\n",
					opt);
			return;
		}
		args = cl.getArgs();
		String datafile = args[0];
		String modelfile = args[1];
		int maxite = Integer.parseInt(cl.getOptionValue("iter", "50"));
		float c = Float.parseFloat(cl.getOptionValue("c", "1"));
		
		ParserTrainer trainer = new ParserTrainer(modelfile);
		trainer.train(datafile, maxite, c);
	}
198553
public void exec(final MainRemote.Script script) throws Exception {
        final File file = File.createTempFile("takes-", ".txt");
        if (!file.delete()) {
            throw new IOException(
                String.format(
                    // @checkstyle LineLength (1 line)
                    "The temporary file '%s' could not be deleted before calling the exec method",
                    file.getAbsolutePath()
                )
            );
        }
        final Method method = this.app.getDeclaredMethod(
            "main", String[].class
        );
        final String[] passed = new String[1 + this.args.length];
        passed[0] = String.format("--port=%s", file.getAbsoluteFile());
        for (int idx = 0; idx < this.args.length; ++idx) {
            passed[idx + 1] = this.args[idx];
        }
        final Thread thread = new Thread(new MainMethod(method, passed));
        thread.start();
        try {
            script.exec(
                URI.create(
                    String.format(
                        "http://localhost:%d",
                        MainRemote.port(file)
                    )
                )
            );
        } catch (final IOException ex) {
            if (!file.delete()) {
                ex.addSuppressed(
                    new IOException(
                        String.format(
                            // @checkstyle LineLength (1 line)
                            "The temporary file '%s' could not be deleted while catching the error",
                            file.getAbsolutePath()
                        )
                    )
                );
            }
            throw ex;
        } finally {
            thread.interrupt();
        }
        if (!file.delete()) {
            throw new IOException(
                String.format(
                    // @checkstyle LineLength (1 line)
                    "The temporary file '%s' could not be deleted after calling the exec method",
                    file.getAbsolutePath()
                )
            );
        }
    }
350424
public void writeFile(File inputFile, String jarPath) throws IOException {

		// Get an input stream on the file.
		FileInputStream fis = new FileInputStream(inputFile);
		try {
			// create the zip entry
			JarEntry entry = new JarEntry(jarPath);
			entry.setTime(inputFile.lastModified());
			writeEntry(fis, entry);

		} finally {
			// close the file stream used to read the file
			fis.close();
		}
	}
671486
void parseOneFile(final Path inputPath, final File outputFolder) throws IOException {
    try (final TFile.Reader.Scanner scanner = this.getScanner(inputPath)) {
      while (!scanner.atEnd()) {
        new LogFileEntry(scanner.entry()).write(outputFolder);
        scanner.advance();
      }
    }
  }
533041
public String transform(File inputFile) {
		final String content;
		try (FileReader reader = new FileReader(inputFile)) {
			content = read(reader);
		} catch (IOException exception) {
			reportError(Messages.SarlDocumentationParser_0, exception);
			return null;
		}
		return transform(content, inputFile);
	}
390660
private void handleFile(final InputGroup group) {
    // Register a group start handler. The start handler will be called
    // with the file name. Then we can open the file.
    group.startHandler(new Handler<String>() {
      @Override
      public void handle(String fileName) {
        final File file = new File(tempDir, String.format("temp-%s-%s", UUID.randomUUID().toString(), fileName));
        input.vertx().fileSystem().open(file.getAbsolutePath(), new Handler<AsyncResult<AsyncFile>>() {
          @Override
          public void handle(AsyncResult<AsyncFile> result) {
            if (result.succeeded()) {
              handleFile(file.getAbsolutePath(), result.result(), group);
            } else if (exceptionHandler != null) {
              exceptionHandler.handle(result.cause());
            }
          }
        });
      }
    });
  }
858368
private static void process(String input, String output) throws Exception
   {
      FileInputStream is = new FileInputStream(input);
      PrintWriter pw = new PrintWriter(new FileWriter(output));

      byte[] buffer = new byte[is.available()];
      is.read(buffer);
      pw.println(ByteArrayHelper.hexdump(buffer, 0, buffer.length, true, 16, ""));

      is.close();
      pw.flush();
      pw.close();
   }
90849
private void openOutputFile(final String outputFileName) throws IOException
	{
		myOutputFile = new File(outputFileName);
		myOutputStream = new FileOutputStream(myOutputFile);
		myStreamWriter = new OutputStreamWriter(myOutputStream, getOutputEncodingCode());
		myBufferedWriter = new BufferedWriter(myStreamWriter);
	}
69211
public void transform(final File inputFile, final List<XMLFilter> filters) throws DITAOTException {
        final File outputFile = new File(inputFile.getAbsolutePath() + FILE_EXTENSION_TEMP);
        transformFile(inputFile, outputFile, filters);
        try {
            deleteQuietly(inputFile);
            moveFile(outputFile, inputFile);
        } catch (final RuntimeException e) {
            throw e;
        } catch (final Exception e) {
            throw new DITAOTException("Failed to replace " + inputFile + ": " + e.getMessage());
        }
    }
790793
public static void move(String input, String output) throws Exception {
		File inputFile = new File(input);
		File outputFile = new File(output);
		try {
			inputFile.renameTo(outputFile);
		} catch (Exception ex) {
			throw new Exception("Can not mv" + input + " to " + output + ex.getMessage());
		}
	}
1125929
public void setOutputfile(String outputfile) {
	try {
	    this.outputfile = ResourceUtil.toResourceExistingParent(pageContext, outputfile);
	    pageContext.getConfig().getSecurityManager().checkFileLocation(this.outputfile);

	}
	catch (PageException e) {
	    this.outputfile = pageContext.getConfig().getTempDirectory().getRealResource(outputfile);
	    if (!this.outputfile.getParentResource().exists()) this.outputfile = null;
	    else if (!this.outputfile.isFile()) this.outputfile = null;
	    else if (!this.outputfile.exists()) {
		ResourceUtil.createFileEL(this.outputfile, false);
		// try {
		// this.outputfile.createNewFile();
		/*
		 * } catch (IOException e1) { this.outputfile=null; }
		 */
	    }
	}
    }
1287290
public static void writeToFile(InputStream inputStream, File file) {
        try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream)) {
            writeToFile(FileCopyUtils.copyToString(inputStreamReader), file, getDefaultCharset());
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to write file", e);
        }
    }
1329570
public static void createFile(File file) throws Exception {
    File dir = new File(file.getAbsolutePath().replace(File.separator + file.getName(), ""));
    if(!dir.exists()) {
      if(!dir.mkdirs()) {
        throw new Exception("Can't create dirs "+dir);
      }
    }
    file.createNewFile();
  }
925339
@Override
    public synchronized void addFile(File pFile, String pRelativePath) throws TTException, IOException {
        // LOGGER.info("Adding file " + pFile.getName());

        int readingAmount = 0;

        @SuppressWarnings("resource")
        FileChannel ch = new RandomAccessFile(pFile, "rw").getChannel();
        FileLock lock = null;

        while (lock == null) {
            try {
                lock = ch.tryLock();
            } catch (OverlappingFileLockException e) {
                // File is already locked in this thread or virtual machine
            }
        }

        // LOGGER.info("Filesize: " + ch.size());

        ByteBuffer buffer = ByteBuffer.allocate(FileData.FILENODESIZE);

        // LOGGER.debug("Successfully initialized byte source.");
        readingAmount += ch.read(buffer);

        // LOGGER.debug("First readAmount: " + readingAmount);
        if (readingAmount <= 0) {
            MetaKey key = new MetaKey(pRelativePath);
            MetaValue value = new MetaValue(FilelistenerReadTrx.emptyFileKey);
            getBucketTransaction().getMetaBucket().put(key, value);

            return;
        }

        long newKey = getBucketTransaction().incrementDataKey();

        if (fileExists(pRelativePath)) {
            removeFile(pRelativePath);
        }

        // Setting a new header file data
        MetaKey key = new MetaKey(pRelativePath);
        MetaValue value = new MetaValue(newKey);

        // And adding it to the meta map
        // LOGGER.debug("Metakeypair setup");
        getBucketTransaction().getMetaBucket().put(key, value);

        // Creating and setting the headerdata.
        FileData headerData = new FileData(newKey, buffer.array(), false);

        getBucketTransaction().setData(headerData);

        // Creating and setting following datas based on the file size.
        FileData data;

        int currentReadingAmount = 0;
        // LOGGER.info("Iterating file content");
        while ((currentReadingAmount = ch.read(buffer = ByteBuffer.allocate(FileData.FILENODESIZE))) > 0) {
            // LOGGER.debug("Curr. read amount: " + currentReadingAmount);
            byte[] slice = Arrays.copyOf(buffer.array(), currentReadingAmount);

            long dataKey = getBucketTransaction().incrementDataKey();
            data = new FileData(dataKey, slice, false);

            getBucketTransaction().setData(data);

            readingAmount += currentReadingAmount;
        }

        ByteArrayDataOutput size = ByteStreams.newDataOutput();
        size.writeInt(readingAmount);

        data = new FileData(getBucketTransaction().incrementDataKey(), size.toByteArray(), true);

        getBucketTransaction().setData(data);

        Preconditions.checkArgument(getBucketTransaction().getData(newKey) != null);
        lock.release();
        ch.close();
    }