001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.vfs2.provider.zip; 019 020import java.nio.charset.Charset; 021import java.nio.charset.StandardCharsets; 022 023import org.apache.commons.vfs2.FileSystem; 024import org.apache.commons.vfs2.FileSystemConfigBuilder; 025import org.apache.commons.vfs2.FileSystemOptions; 026 027/** 028 * Configures {@link FileSystemOptions}s. 029 */ 030public class ZipFileSystemConfigBuilder extends FileSystemConfigBuilder { 031 032 private static final String PREFIX = ZipFileSystemConfigBuilder.class.getName(); 033 private static final ZipFileSystemConfigBuilder INSTANCE = new ZipFileSystemConfigBuilder(); 034 private static final String KEY_CHARSET = PREFIX + ".charset"; 035 036 /** 037 * Gets the singleton instance. 038 * 039 * @return the singleton instance. 040 */ 041 public static final ZipFileSystemConfigBuilder getInstance() { 042 return INSTANCE; 043 } 044 045 /** 046 * Constructs a new instance. 047 */ 048 private ZipFileSystemConfigBuilder() { 049 super("zip."); 050 } 051 052 /** 053 * Gets the Charset from the FileSystemOptions or {@link StandardCharsets#UTF_8} if absent. 054 * 055 * @param fileSystemOptions The source FileSystemOptions. 056 * @return the Charset from the FileSystemOptions. 057 */ 058 public Charset getCharset(final FileSystemOptions fileSystemOptions) { 059 return getParamOrDefault(fileSystemOptions, KEY_CHARSET, StandardCharsets.UTF_8); 060 } 061 062 @Override 063 protected Class<? extends FileSystem> getConfigClass() { 064 return ZipFileSystem.class; 065 } 066 067 /** 068 * Sets the Charset in the FileSystemOptions. 069 * 070 * @param fileSystemOptions The target FileSystemOptions. 071 * @param charset The Charset to set. 072 */ 073 public void setCharset(final FileSystemOptions fileSystemOptions, final Charset charset) { 074 setParam(fileSystemOptions, KEY_CHARSET, charset); 075 } 076 077}