Class Ccp4Header

java.lang.Object
org.biojava.nbio.structure.io.density.Ccp4Header

public class Ccp4Header extends Object
Recognises CCP4/MRC map files by their header.

This is a cheap but effective guard against a cached file that is not actually a map. A misbehaving or overloaded server can answer with an HTML error page and an HTTP 200, in which case nothing about the status code or the content length reveals the problem — but the missing MAP  stamp does, turning a silent failure into a clean cache miss.

Since:
7.3.0
Author:
Amr ALHOSSARY
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The stamp itself: the three letters of "MAP" followed by a space.
    static final int
    Byte offset of the four-character format stamp within a CCP4/MRC header.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isCcp4(File file)
    Checks whether a file is a CCP4/MRC map.
    static boolean
    Checks whether a stream carries a CCP4/MRC map header.
    static boolean
    Same as isCcp4(File) but reports a problem rather than propagating it, for use in cache-validity checks where an unreadable file and an invalid one lead to the same action.

    Methods inherited from class java.lang.Object

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

    • MAP_STAMP_OFFSET

      public static final int MAP_STAMP_OFFSET
      Byte offset of the four-character format stamp within a CCP4/MRC header. It sits in word 53 of the 256-word header.
      See Also:
    • MAP_STAMP

      public static final String MAP_STAMP
      The stamp itself: the three letters of "MAP" followed by a space.
      See Also:
  • Method Details

    • isCcp4

      public static boolean isCcp4(File file) throws IOException
      Checks whether a file is a CCP4/MRC map. Gzipped files are decompressed on the fly, so .map.gz works as well as .ccp4.
      Parameters:
      file - the file to check
      Returns:
      true if the CCP4 stamp is present
      Throws:
      IOException - if the file could not be read
    • isCcp4

      public static boolean isCcp4(InputStream in) throws IOException
      Checks whether a stream carries a CCP4/MRC map header. The stream is read from its current position and is not closed; it is not un-read afterwards, so pass a fresh stream or one that supports marking.
      Parameters:
      in - the stream to check, already decompressed
      Returns:
      true if the CCP4 stamp is present
      Throws:
      IOException - if the stream could not be read
    • isCcp4Quietly

      public static boolean isCcp4Quietly(File file)
      Same as isCcp4(File) but reports a problem rather than propagating it, for use in cache-validity checks where an unreadable file and an invalid one lead to the same action.
      Parameters:
      file - the file to check
      Returns:
      true if the file is readable and carries the CCP4 stamp