Class ARCUtils


  • public final class ARCUtils
    extends Object
    Various utilities that do stuff that ARCWriter does not provide. Also includes method for converting an ARCRecord to a byte array.
    • Method Detail

      • insertARCFile

        public static void insertARCFile​(File arcFile,
                                         org.archive.io.arc.ARCWriter aw)
        Insert the contents of an ARC file (skipping an optional initial filedesc: header) in another ARCfile.
        Parameters:
        arcFile - An ARC file to read.
        aw - A place to write the arc records
        Throws:
        IOFailure - if there are problems reading the file.
      • createARCWriter

        public static org.archive.io.arc.ARCWriter createARCWriter​(File newFile)
        Create new ARCWriter, writing to arcfile newFile.
        Parameters:
        newFile - the ARCfile, that the ARCWriter writes to.
        Returns:
        new ARCWriter, writing to arcfile newFile.
      • writeFileToARC

        public static void writeFileToARC​(org.archive.io.arc.ARCWriter aw,
                                          File file,
                                          String uri,
                                          String mime)
        Write a file to an ARC file. The writing is done by an existing ARCWriter. An ARCRecord will be added, which contains a header and the contents of the file. The date of the record written will be set to the lastModified value of the file being written.
        Parameters:
        aw - The ARCWriter doing the writing
        file - The file we want to write to the ARC file
        uri - The uri for the ARCRecord being written
        mime - The mimetype for the ARCRecord being written
        Throws:
        ArgumentNotValid - if any arguments aw and file are null and arguments uri and mime are null or empty.
      • getToolsARCWriter

        public static org.archive.io.arc.ARCWriter getToolsARCWriter​(PrintStream stream,
                                                                     File destinationArcfile)
                                                              throws IOException
        Return an ARCWriter suitable for the tools ArcMerge and ArcWrap.
        Parameters:
        stream - the given PrintStream.
        destinationArcfile - the given destination ARC file.
        Returns:
        ARCWriter to be used by tools ArcMerge and ArcWrap
        Throws:
        IOException - redirect from ARCWriter constructure
      • readARCRecord

        public static byte[] readARCRecord​(org.archive.io.arc.ARCRecord in)
                                    throws IOException
        Read the contents of an ARC record into a byte array.
        Parameters:
        in - An ARC record to read from. After reading, the ARC Record will no longer have its own data available for reading.
        Returns:
        A byte array containing the contents of the ARC record. Note that the size of this may be different from the size given in the ARC record metadata.
        Throws:
        IOException - If there is an error reading the data, or if the record is longer than Integer.MAX_VALUE (since we can't make bigger arrays).
      • getHeadersFromARCFile

        public static Map<String,​Object> getHeadersFromARCFile​(InputStream in,
                                                                     Long offset)
                                                              throws IOException
        TODO write unit test.
        Parameters:
        in - pointing at start of ARC record.
        offset - into ARC file.
        Returns:
        pairwise headers.
        Throws:
        IOException - if fails to read ARC files or ARC files isn't valid.
      • isARC

        public static boolean isARC​(String filename)
        Check if the filename belongs to an ARC file.
        Parameters:
        filename - a given filename
        Returns:
        true, if the filename converted to lowercase ends with .arc or .arc.gz