当前位置: 首页>>代码示例>>Java>>正文


Java FileHistory类代码示例

本文整理汇总了Java中jline.console.history.FileHistory的典型用法代码示例。如果您正苦于以下问题:Java FileHistory类的具体用法?Java FileHistory怎么用?Java FileHistory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileHistory类属于jline.console.history包,在下文中一共展示了FileHistory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadHistoryFromFile

import jline.console.history.FileHistory; //导入依赖的package包/类
/**
 * Load terminal command history from a file.
 *
 * @param p_file
 *         File to load the history from and append new commands to.
 */
private void loadHistoryFromFile(final String p_file) throws TerminalException {
    File file = new File(p_file);

    if (!file.exists()) {
        try {
            if (!file.createNewFile()) {
                throw new TerminalException("Creating new history file " + p_file + " failed");
            }
        } catch (final IOException ignored) {
        }
    }

    try {
        m_history = new FileHistory(new File(p_file));
        m_consoleReader.setHistory(m_history);
    } catch (final IOException e) {
        throw new TerminalException("Reading history " + p_file + " failed", e);
    }
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:26,代码来源:TerminalClient.java

示例2: setupHistory

import jline.console.history.FileHistory; //导入依赖的package包/类
private boolean setupHistory() throws IOException {
    // Create history file
    File historyFile = new File(historyFilename);
    boolean fileCreated = historyFile.createNewFile();
    FileHistory history = new FileHistory(historyFile);
    console.setHistory(history);

    // Make sure history is saved on shutdown
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        try {
            history.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }));

    return fileCreated;
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:19,代码来源:GraqlShell.java

示例3: loadHistory

import jline.console.history.FileHistory; //导入依赖的package包/类
@Nullable
private static FileHistory loadHistory() {
    try {
        File userHome = new File( System.getProperty( "user.home", "." ) );
        @Nullable
        String historyFileLocation = System.getProperty( "osgiaas.cli.history" );
        File historyFile;
        if ( historyFileLocation == null ) {
            historyFile = new File( userHome, ".osgiaas_cli_history" );
        } else {
            historyFile = new File( historyFileLocation );
        }
        return new FileHistory( historyFile );
    } catch ( Exception e ) {
        System.err.println( "Unable to load osgiaas-cli history: " + e );
        return null;
    }
}
 
开发者ID:renatoathaydes,项目名称:osgiaas,代码行数:19,代码来源:CliRun.java

示例4: buildInstance

import jline.console.history.FileHistory; //导入依赖的package包/类
public static HeroicInteractiveShell buildInstance(
    final List<CommandDefinition> commands, FileInputStream input
) throws Exception {
    final ConsoleReader reader = new ConsoleReader("heroicsh", input, System.out, null);

    final FileHistory history = setupHistory(reader);

    if (history != null) {
        reader.setHistory(history);
    }

    reader.setPrompt(String.format("heroic> "));
    reader.addCompleter(new StringsCompleter(
        ImmutableList.copyOf(commands.stream().map((d) -> d.getName()).iterator())));
    reader.setHandleUserInterrupt(true);

    return new HeroicInteractiveShell(reader, commands, history);
}
 
开发者ID:spotify,项目名称:heroic,代码行数:19,代码来源:HeroicInteractiveShell.java

示例5: JLineDevice

import jline.console.history.FileHistory; //导入依赖的package包/类
public JLineDevice(InputStream in, PrintStream out) throws IOException {
    File hfile = new File(HFILE);
    if (!hfile.exists()) {
        File parentFile = hfile.getParentFile();
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
        hfile.createNewFile();
    }
    writer = new PrintWriter(out, true);
    reader = new ConsoleReader(in, out);
    history = new FileHistory(hfile);
    reader.setHistory(history);

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            writeHistory();
        }
    }));
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:22,代码来源:JLineDevice.java

示例6: enableHistoryFrom

import jline.console.history.FileHistory; //导入依赖的package包/类
void enableHistoryFrom(String file) {
    try {
        Path directory = Paths.get(System.getProperty("user.home"), ".jline");
        Path historyFile = Paths.get(directory.toString(), file);
        if (!directory.toFile().exists()) {
            Files.createDirectories(directory);
        }
        if (!historyFile.toFile().exists()) {
            Files.createFile(historyFile);
        }
        history = new FileHistory(historyFile.toFile());
        consoleReader.setHistory(history);
        consoleReader.setHistoryEnabled(true);
    } catch (IOException e) {
        throw new IllegalStateException("Can't create history file", e);
    }
}
 
开发者ID:dfoerderreuther,项目名称:console-builder,代码行数:18,代码来源:ConsoleReaderWrapper.java

示例7: getJLineHistory

import jline.console.history.FileHistory; //导入依赖的package包/类
/**
 * Load the History from disk if a $HOME directory is defined, otherwise fall back to using an in-memory history object
 * 
 * @return
 * @throws IOException
 */
protected History getJLineHistory() throws IOException {
  String home = System.getProperty("HOME");
  if (null == home) {
    home = System.getenv("HOME");
  }
  
  // Get the home directory
  File homeDir = new File(home);
  
  // Make sure it actually exists
  if (homeDir.exists() && homeDir.isDirectory()) {
    // Check for, and create if necessary, the directory for cosmos to use
    File historyDir = new File(homeDir, ".cosmos");
    if (!historyDir.exists() && !historyDir.mkdirs()) {
      log.warn("Could not create directory for history at {}, using temporary history.", historyDir);
    }
    
    // Get a file for jline history
    File historyFile = new File(historyDir, "history");
    return new FileHistory(historyFile);
  } else {
    log.warn("Home directory not found: {}, using temporary history", homeDir);
    return new MemoryHistory();
  }
}
 
开发者ID:joshelser,项目名称:cosmos,代码行数:32,代码来源:CosmosConsole.java

示例8: run

import jline.console.history.FileHistory; //导入依赖的package包/类
@Override
public void run() {
    while (!isInterrupted()) {
        try {
            String line = console.readLine("> ");
            if (line != null) {
                line = line.trim();
                if (line.isEmpty()) {
                    logger.log(Level.INFO, "{0}\\n isn''t a command", ChatColor.DARK_RED);
                    continue;
                }
                line = parser.parse(line);
                String[] args = line.split(" ");
                commandHandler.dispatchCommand(consoleSender, args[0], ArrayUtils.sub(args));
                // flush history
                try {
                    ((FileHistory) console.getHistory()).flush();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } catch (Throwable t) {
            logger.log(Level.INFO, "Error in input thread", t);
        }
    }
}
 
开发者ID:daboross,项目名称:minecraft-commandline-interface,代码行数:27,代码来源:InputHandlerThread.java

示例9: start

import jline.console.history.FileHistory; //导入依赖的package包/类
public void start() throws Exception {
    console = new ConsoleReader();
    console.getTerminal().setEchoEnabled(false);
    console.setPrompt("\u001B[32menkan\u001B[0m> ");
    History history = new FileHistory(new File(System.getProperty("user.home"), ".enkan_history"));
    console.setHistory(history);

    CandidateListCompletionHandler handler = new CandidateListCompletionHandler();
    console.setCompletionHandler(handler);
    consoleHandler = new ConsoleHandler(console);
    clientThread.execute(consoleHandler);
    clientThread.shutdown();
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:14,代码来源:ReplClient.java

示例10: addShutdownHookToFlushHistory

import jline.console.history.FileHistory; //导入依赖的package包/类
private static void addShutdownHookToFlushHistory(@Nonnull final Logger logger, final FileHistory history) {
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                history.flush();
            } catch (IOException e) {
                logger.printError("Failed to save history:\n" + e.getMessage());
            }
        }
    });
}
 
开发者ID:neo4j,项目名称:cypher-shell,代码行数:13,代码来源:FileHistorian.java

示例11: setupHistory

import jline.console.history.FileHistory; //导入依赖的package包/类
private void setupHistory(ConsoleReader reader)
{
  File historyFile = new File(StramClientUtils.getUserDTDirectory(), "cli_history");
  historyFile.getParentFile().mkdirs();
  try {
    topLevelHistory = new FileHistory(historyFile);
    reader.setHistory(topLevelHistory);
    historyFile = new File(StramClientUtils.getUserDTDirectory(), "cli_history_clp");
    changingLogicalPlanHistory = new FileHistory(historyFile);
  } catch (IOException ex) {
    System.err.printf("Unable to open %s for writing.", historyFile);
  }
}
 
开发者ID:apache,项目名称:apex-core,代码行数:14,代码来源:ApexCli.java

示例12: setupHistory

import jline.console.history.FileHistory; //导入依赖的package包/类
private static FileHistory setupHistory(final ConsoleReader reader) throws IOException {
    final String home = System.getProperty("user.home");

    if (home == null) {
        return null;
    }

    return new FileHistory(new File(home, ".heroicsh-history"));
}
 
开发者ID:spotify,项目名称:heroic,代码行数:10,代码来源:HeroicInteractiveShell.java

示例13: getConsoleReader

import jline.console.history.FileHistory; //导入依赖的package包/类
public ConsoleReader getConsoleReader(InputStream inputStream,
        FileHistory fileHistory) throws IOException {
    Terminal terminal = TerminalFactory.create();
    try {
        terminal.init();
    } catch (Exception e) {
        // For backwards compatibility with code that used to use this lib
        // and expected only IOExceptions, convert back to that. We can't
        // use IOException(Throwable) constructor, which is only JDK 1.6 and
        // later.
        final IOException ioException = new IOException(e.toString());
        ioException.initCause(e);
        throw ioException;
    }
    if (inputStream != null) {
        // ### NOTE:  fix for sf.net bug 879425.
        consoleReader = new ConsoleReader(inputStream, System.out);
    } else {
        consoleReader = new ConsoleReader();
    }

    consoleReader.addCompleter(new SqlLineCompleter(this));
    consoleReader.setHistory(fileHistory);
    consoleReader.setHandleUserInterrupt(true); // CTRL-C handling
    consoleReader.setExpandEvents(false);

    return consoleReader;
}
 
开发者ID:mozafari,项目名称:verdict,代码行数:29,代码来源:SqlLine.java

示例14: initHistory

import jline.console.history.FileHistory; //导入依赖的package包/类
private void initHistory() {
  try {
    String historyPath = HOME_DIR + File.separator + HISTORY_FILE;
    if ((new File(HOME_DIR)).exists()) {
      reader.setHistory(new FileHistory(new File(historyPath)));
    } else {
      System.err.println("ERROR: home directory : '" + HOME_DIR +"' does not exist.");
    }
  } catch (Exception e) {
    System.err.println(e.getMessage());
  }
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:13,代码来源:TajoCli.java

示例15: setHistoryFile

import jline.console.history.FileHistory; //导入依赖的package包/类
public void setHistoryFile(File f){
    histFile = f;
    try{
        history  = new FileHistory(histFile);
        console.setHistory(history);
    }catch(IOException ex){
        throw new RuntimeException ("Unable to set history file.", ex);
    }
}
 
开发者ID:vladimirvivien,项目名称:clamshell-cli,代码行数:10,代码来源:CliConsole.java


注:本文中的jline.console.history.FileHistory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。