Class LockWriter


  • public class LockWriter
    extends java.lang.Object
    Writes records to a SAMP Standard Profile hub lockfile.
    Since:
    15 Jul 2008
    Author:
    Mark Taylor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte[] linesep_  
      private java.io.OutputStream out_  
      private static java.util.regex.Pattern TOKEN_PATTERN  
      private static java.lang.String TOKEN_REGEX  
    • Constructor Summary

      Constructors 
      Constructor Description
      LockWriter​(java.io.OutputStream out)
      Constructs a writer for writing to a given output stream.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the output stream.
      private static byte[] getLineSeparator()
      Returns the platform-specific line separator sequence as an array of bytes.
      static void setLockPermissions​(java.io.File file)
      Sets the permissions on a given file suitably for a SAMP Standard Profile lockfile.
      void writeAssignment​(java.lang.String name, java.lang.String value)
      Writes a single assignment to the lockfile.
      void writeAssignments​(java.util.Map map)
      Writes all the assignments in a given map to the lockfile.
      void writeComment​(java.lang.String comment)
      Writes a comment line to the lockfile.
      void writeLine()
      Writes a blank line to the lockfile.
      protected void writeLine​(java.lang.String line)
      Writes a line of text to the lockfile, terminated with a line-end.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • out_

        private final java.io.OutputStream out_
      • linesep_

        private static final byte[] linesep_
      • TOKEN_PATTERN

        private static final java.util.regex.Pattern TOKEN_PATTERN
    • Constructor Detail

      • LockWriter

        public LockWriter​(java.io.OutputStream out)
        Constructs a writer for writing to a given output stream.
        Parameters:
        out - output stream
    • Method Detail

      • writeAssignments

        public void writeAssignments​(java.util.Map map)
                              throws java.io.IOException
        Writes all the assignments in a given map to the lockfile.
        Parameters:
        map - assignment set to output
        Throws:
        java.io.IOException
      • writeAssignment

        public void writeAssignment​(java.lang.String name,
                                    java.lang.String value)
                             throws java.io.IOException
        Writes a single assignment to the lockfile.
        Parameters:
        name - assignment key
        value - assignment value
        Throws:
        java.io.IOException
      • writeComment

        public void writeComment​(java.lang.String comment)
                          throws java.io.IOException
        Writes a comment line to the lockfile.
        Parameters:
        comment - comment text
        Throws:
        java.io.IOException
      • writeLine

        public void writeLine()
                       throws java.io.IOException
        Writes a blank line to the lockfile.
        Throws:
        java.io.IOException
      • writeLine

        protected void writeLine​(java.lang.String line)
                          throws java.io.IOException
        Writes a line of text to the lockfile, terminated with a line-end.
        Parameters:
        line - line to write
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Closes the output stream. May be required to ensure that all data is written.
        Throws:
        java.io.IOException
      • setLockPermissions

        public static void setLockPermissions​(java.io.File file)
                                       throws java.io.IOException
        Sets the permissions on a given file suitably for a SAMP Standard Profile lockfile. This means that nobody apart from the file's owner can read it.
        Parameters:
        file - file to set access permissions on
        Throws:
        java.io.IOException
      • getLineSeparator

        private static final byte[] getLineSeparator()
        Returns the platform-specific line separator sequence as an array of bytes.
        Returns:
        line separator sequence