Package com.dbdeploy.scripts

Source Code of com.dbdeploy.scripts.FilenameParser

package com.dbdeploy.scripts;

import com.dbdeploy.exceptions.UnrecognisedFilenameException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FilenameParser {
  private final Pattern pattern;

  public FilenameParser() {
    pattern = Pattern.compile("(\\d+).*");
  }

  public long extractIdFromFilename(String filename) throws UnrecognisedFilenameException {
    Matcher matches = pattern.matcher(filename);
    if (!matches.matches() || matches.groupCount() != 1)
      throw new UnrecognisedFilenameException("Could not extract a change script number from filename: " + filename);
   
    return Long.parseLong(matches.group(1));
   }

}
TOP

Related Classes of com.dbdeploy.scripts.FilenameParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.