001/** 002 * 003 * Copyright © 2017 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 */ 017package org.jivesoftware.smackx.httpfileupload; 018 019import org.jivesoftware.smack.util.Objects; 020import org.jxmpp.jid.DomainBareJid; 021 022public class UploadService { 023 024 enum Version { 025 v0_2, 026 v0_3, 027 }; 028 029 private final DomainBareJid address; 030 private final Version version; 031 private final Long maxFileSize; 032 033 UploadService(DomainBareJid address, Version version) { 034 this(address, version, null); 035 } 036 037 UploadService(DomainBareJid address, Version version, Long maxFileSize) { 038 this.address = Objects.requireNonNull(address); 039 this.version = version; 040 this.maxFileSize = maxFileSize; 041 } 042 043 public DomainBareJid getAddress() { 044 return address; 045 } 046 047 public Version getVersion() { 048 return version; 049 } 050 051 public boolean hasMaxFileSizeLimit() { 052 return maxFileSize != null; 053 } 054 055 public Long getMaxFileSize() { 056 return maxFileSize; 057 } 058 059 public boolean acceptsFileOfSize(long size) { 060 if (!hasMaxFileSizeLimit()) { 061 return true; 062 } 063 064 return size <= maxFileSize; 065 } 066}