/* * [Splitter.java] * * Summary: splits files into pieces based on embedded markers. * * Copyright: (c) 2004-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.1 2006-03-05 reformat with IntelliJ, add Javadoc * 1.2 2007-05-22 add PAD and icon. Tidy with IntelliJ inspector. * 1.3 2008-03-21 allow user to specify the encoding. * 1.4 2014-05-17 allow multiple files and dirs on comand line */ package com.mindprod.splitter; import com.mindprod.commandline.CommandLine; import com.mindprod.common18.EIO; import com.mindprod.common18.ST; import com.mindprod.filter.AllButSVNDirectoriesFilter; import com.mindprod.filter.ExtensionListFilter; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.IOException; import java.io.Writer; import java.nio.charset.Charset; import static java.lang.System.*; /** * splits files into pieces based on embedded markers. *

* splits a large file into pieces based on embedded tags in it that tell it where to put the pieces. The <split tags * are case-insensitive * * @author Roedy Green, Canadian Mind Products * @version 1.4 2014-05-17 allow multiple files and dirs on comand line * @since 2004 */ public final class Splitter { // declarations private static final int FIRST_COPYRIGHT_YEAR = 2004; /** * undisplayed copyright notice */ @SuppressWarnings( { "UnusedDeclaration" } ) private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 2004-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; @SuppressWarnings( { "UnusedDeclaration" } ) private static final String RELEASE_DATE = "2014-05-17"; /** * syntax of command line */ private static final String USAGE = "\nSplitter.jar -charset=UTF8 [-q] file [file -s dir...]"; /** * embedded version string. */ @SuppressWarnings( { "UnusedDeclaration" } ) private static final String VERSION_STRING = "1.4"; /** * keeps track of which files have been used previously. If they have, we isAppending. */ private static final FileStack dupsStack = new FileStack(); /** * keeps track of nesting of ... tags do not balance." ); } HunkIO.deleteAndRename( baseFile, fileToProcess ); } catch ( IOException e ) { err.println(); e.printStackTrace( err ); err.println( "I/O Exception splitter aborted." ); err.println(); } }// /method /** * We just parsed a = 0 ) { // output stuff ahead of the tag squirt( fromIndex, nextTagIndex ); if ( nextTagIndex + "".length() < originalLength ) { int startFilename = nextTagIndex + " at tail end of filename. int endTag = big.indexOf( '>', startFilename ); if ( endTag < 0 ) { throw new IllegalArgumentException( "." ); } String filename = big.substring( startFilename, endTag ) .trim(); if ( filename.length() <= 0 ) { throw new IllegalArgumentException( "".length() ) .equalsIgnoreCase( "/split>" ) ) { // was // bypass tag fromIndex = nextTagIndex + "".length(); processSplitEndTag(); } else { // false alarm was not a split tag, some other sort of = 1 && args[ 0 ].startsWith( "-charset=" ) ) { cs = Charset.forName( ST.chopLeadingString( args[ 0 ], "-charset;" ) ); args[ 0 ] = null; /* hide from CommandLine */ } else { cs = Charset.defaultCharset(); } // gather all the files mentioned on the command line. // either directories, files, *.*, with -s and subdirs option. out.println( "Gathering files to split..." ); CommandLine commandLine = new CommandLine( args, new AllButSVNDirectoriesFilter(), new ExtensionListFilter( ExtensionListFilter.COMMON_TEXT_EXTENSIONS ) ); final boolean quiet = commandLine.isQuiet(); if ( commandLine.size() == 0 ) { throw new IllegalArgumentException( "No files found to process\n" + USAGE ); } for ( File file : commandLine ) { try { processFile( quiet, file ); } catch ( Exception e ) { err.println(); e.printStackTrace( err ); err.println( " in file " + EIO.getCanOrAbsPath( file ) ); err.println(); } } // end for }// /method // /methods } // end Splitter