1 /* 2 3 dsh-compress Compression utility classes. 4 Copyright (c) 2014-2017 held jointly by the individual authors. 5 6 This library is free software; you can redistribute it and/or modify it 7 under the terms of the GNU Lesser General Public License as published 8 by the Free Software Foundation; either version 3 of the License, or (at 9 your option) any later version. 10 11 This library is distributed in the hope that it will be useful, but WITHOUT 12 ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 License for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with this library; if not, write to the Free Software Foundation, 18 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 19 20 > http://www.fsf.org/licensing/licenses/lgpl.html 21 > http://www.opensource.org/licenses/lgpl-license.php 22 23 */ 24 package org.dishevelled.compress; 25 26 import java.util.LinkedHashMap; 27 import java.util.Map; 28 29 import org.apache.commons.compress.compressors.FileNameUtil; 30 31 /** 32 * Utility code for the block compressed gzip (BGZF) compression format. 33 * 34 * @since 1.3 35 * @author Michael Heuer 36 */ 37 public abstract class BgzfUtils 38 { 39 private static final FileNameUtil fileNameUtil; 40 41 static 42 { 43 final Map<String, String> uncompressSuffix = new LinkedHashMap<String, String>(); 44 uncompressSuffix.put(".bgz", ""); 45 uncompressSuffix.put(".bgzf", ""); 46 fileNameUtil = new FileNameUtil(uncompressSuffix, ".bgz"); 47 } 48 49 50 /** 51 * Private constructor to prevent instantiation of this utility class. 52 */ 53 private BgzfUtils() 54 { 55 // empty 56 } 57 58 59 /** 60 * Detects common block compressed gzip (BGZF) suffixes in the given filename. 61 * 62 * @param filename name of a file 63 * @return {@code true} if the filename has a common block compressed gzip (BGZF) suffix, 64 * {@code false} otherwise 65 */ 66 public static boolean isCompressedFilename(final String filename) 67 { 68 return fileNameUtil.isCompressedFilename(filename); 69 } 70 71 /** 72 * Maps the given name of a block compressed gzip (BGZF) file to the name that the 73 * file should have after uncompression. Commonly used file type specific 74 * suffixes like ".bgz" or ".bgzf" are automatically detected and 75 * correctly mapped. Any filenames with the generic ".bgz" suffix 76 * (or any other generic bgzf suffix) is mapped to a name without that 77 * suffix. If no bgzf suffix is detected, then the filename is returned 78 * unmapped. 79 * 80 * @param filename name of a file 81 * @return name of the corresponding uncompressed file 82 */ 83 public static String getUncompressedFilename(final String filename) 84 { 85 return fileNameUtil.getUncompressedFilename(filename); 86 } 87 88 /** 89 * Maps the given filename to the name that the file should have after 90 * compression with block compressed gzip (BGZF). Currently this method simply appends the suffix 91 * ".bgz" to the filename, but a future version may implement a more complex 92 * mapping if a new widely used naming pattern emerges. 93 * 94 * @param filename name of a file 95 * @return name of the corresponding compressed file 96 */ 97 public static String getCompressedFilename(final String filename) 98 { 99 return fileNameUtil.getCompressedFilename(filename); 100 } 101 }