UploadService.java

  1. /**
  2.  *
  3.  * Copyright © 2017 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.httpfileupload;

  18. import org.jivesoftware.smack.util.Objects;

  19. import org.jxmpp.jid.DomainBareJid;

  20. public class UploadService {

  21.     public enum Version {
  22.         /**
  23.          * Upload service as specified in XEP-0363 v0.2 or lower.
  24.          *
  25.          * @see <a href="https://xmpp.org/extensions/attic/xep-0363-0.2.5.html">XEP-0363 v0.2.5</a>
  26.          */
  27.         v0_2,

  28.         /**
  29.          * Upload service as specified in XEP-0363 v0.3 or higher.
  30.          *
  31.          * @see <a href="https://xmpp.org/extensions/attic/xep-0363-0.4.0.html">XEP-0363 v0.4.0</a>
  32.          */
  33.         v0_3,
  34.     }

  35.     private final DomainBareJid address;
  36.     private final Version version;
  37.     private final Long maxFileSize;

  38.     UploadService(DomainBareJid address, Version version) {
  39.         this(address, version, null);
  40.     }

  41.     UploadService(DomainBareJid address, Version version, Long maxFileSize) {
  42.         this.address = Objects.requireNonNull(address);
  43.         this.version = version;
  44.         this.maxFileSize = maxFileSize;
  45.     }

  46.     public DomainBareJid getAddress() {
  47.         return address;
  48.     }

  49.     public Version getVersion() {
  50.         return version;
  51.     }

  52.     public boolean hasMaxFileSizeLimit() {
  53.         return maxFileSize != null;
  54.     }

  55.     public Long getMaxFileSize() {
  56.         return maxFileSize;
  57.     }

  58.     public boolean acceptsFileOfSize(long size) {
  59.         if (!hasMaxFileSizeLimit()) {
  60.             return true;
  61.         }

  62.         return size <= maxFileSize;
  63.     }
  64. }