diff --git a/src/main/java/it/tdlight/tdlight/Init.java b/src/main/java/it/tdlight/tdlight/Init.java index 7f6a3f0..2bf0a39 100644 --- a/src/main/java/it/tdlight/tdlight/Init.java +++ b/src/main/java/it/tdlight/tdlight/Init.java @@ -33,7 +33,7 @@ public class Init { * * @throws CantLoadLibrary An exception that is thrown when the LoadLibrary class fails to load the library. */ - public synchronized static void start() throws Throwable { + public synchronized static void start() throws CantLoadLibrary { if (!started) { Os os = LoadLibrary.getOs(); diff --git a/src/main/java/it/tdlight/tdlight/TdCallback.java b/src/main/java/it/tdlight/tdlight/TdCallback.java deleted file mode 100644 index 153462a..0000000 --- a/src/main/java/it/tdlight/tdlight/TdCallback.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2018. Ernesto Castellotti - * This file is part of JTdlib. - * - * JTdlib is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * JTdlib is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with JTdlib. If not, see . - */ - -package it.tdlight.tdlight; - -import it.tdlight.tdlight.utils.CloseCallback; -import it.tdlight.tdlight.utils.ErrorCallback; -import it.tdlight.tdlight.utils.ReceiveCallback; - -/** - * Interface of callback for interaction with TDLib. - */ -public class TdCallback { - private ReceiveCallback receiveCallback; - private ErrorCallback errorCallback; - private CloseCallback closeCallback; - - /** - * Creates a new TdCallback. - * - * @param receiveCallback Interface of callback for receive incoming update or request response. - * @param errorCallback Interface of callback for receive incoming error response. - * @param closeCallback Interface of callback for receive notification of closing Tdlib. - */ - public TdCallback(ReceiveCallback receiveCallback, ErrorCallback errorCallback, CloseCallback closeCallback) { - this.receiveCallback = receiveCallback; - this.errorCallback = errorCallback; - this.closeCallback = closeCallback; - } - - /** - * Creates a new TdCallback. - * - * @param receiveCallback Interface of callback for receive incoming update or request response. - */ - public TdCallback(ReceiveCallback receiveCallback) { - this.receiveCallback = receiveCallback; - } - - /** - * Creates a new TdCallback. - * - * @param errorCallback Interface of callback for receive incoming error response. - */ - public TdCallback(ErrorCallback errorCallback) { - this.errorCallback = errorCallback; - } - - /** - * Creates a new TdCallback. - * - * @param closeCallback Interface of callback for receive notification of closing Tdlib. - */ - public TdCallback(CloseCallback closeCallback) { - this.closeCallback = closeCallback; - } - - /** - * Creates a new TdCallback. - * - * @param receiveCallback Interface of callback for receive incoming update or request response. - * @param errorCallback Interface of callback for receive incoming error response. - */ - public TdCallback(ReceiveCallback receiveCallback, ErrorCallback errorCallback) { - this.receiveCallback = receiveCallback; - this.errorCallback = errorCallback; - } - - /** - * Creates a new TdCallback. - * - * @param errorCallback Interface of callback for receive incoming error response. - * @param closeCallback Interface of callback for receive notification of closing Tdlib. - */ - public TdCallback(ErrorCallback errorCallback, CloseCallback closeCallback) { - this.errorCallback = errorCallback; - this.closeCallback = closeCallback; - } - - /** - * Creates a new TdCallback. - * - * @param receiveCallback Interface of callback for receive incoming update or request response. - * @param closeCallback Interface of callback for receive notification of closing Tdlib. - */ - public TdCallback(ReceiveCallback receiveCallback, CloseCallback closeCallback) { - this.receiveCallback = receiveCallback; - this.closeCallback = closeCallback; - } - - /** - * Get ReceiveCallback. - * - * @return This method return ReceiveCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null. - */ - public ReceiveCallback getReceiveCallback() { - if (this.receiveCallback == null) { - return response -> { - }; - } - - return this.receiveCallback; - } - - /** - * Get ErrorCallback. - * - * @return This method return ErrorCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null. - */ - public ErrorCallback getErrorCallback() { - if (this.errorCallback == null) { - return error -> { - }; - } - - return this.errorCallback; - } - - /** - * Get CloseCallback. - * - * @return This method return CloseCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null. - */ - public CloseCallback getCloseCallback() { - if (this.closeCallback == null) { - return () -> { - }; - } - - return this.closeCallback; - } -} diff --git a/src/main/java/it/tdlight/tdlight/utils/CantLoadLibrary.java b/src/main/java/it/tdlight/tdlight/utils/CantLoadLibrary.java index 10de4c3..1b32e51 100644 --- a/src/main/java/it/tdlight/tdlight/utils/CantLoadLibrary.java +++ b/src/main/java/it/tdlight/tdlight/utils/CantLoadLibrary.java @@ -20,7 +20,7 @@ package it.tdlight.tdlight.utils; /** * An exception that is thrown when the LoadLibrary class fails to load the library. */ -public class CantLoadLibrary extends RuntimeException { +public class CantLoadLibrary extends Exception { /** * Creates a new CantLoadLibrary exception. */ diff --git a/src/main/java/it/tdlight/tdlight/utils/LoadLibrary.java b/src/main/java/it/tdlight/tdlight/utils/LoadLibrary.java index 067b499..8dd4f84 100644 --- a/src/main/java/it/tdlight/tdlight/utils/LoadLibrary.java +++ b/src/main/java/it/tdlight/tdlight/utils/LoadLibrary.java @@ -49,7 +49,7 @@ public class LoadLibrary { * @param libname The name of the library. * @throws CantLoadLibrary An exception that is thrown when the LoadLibrary class fails to load the library. */ - public static void load(String libname) throws Throwable { + public static void load(String libname) throws CantLoadLibrary { if (libname == null || libname.trim().isEmpty()) { throw new IllegalArgumentException(); } @@ -64,16 +64,16 @@ public class LoadLibrary { libraryLoaded.put(libname, true); } - private static void loadLibrary(String libname) throws Throwable { + private static void loadLibrary(String libname) throws CantLoadLibrary { Arch arch = getCpuArch(); Os os = getOs(); if (arch == Arch.unknown) { - throw new CantLoadLibrary().initCause(new IllegalStateException("Arch: \"" + System.getProperty("os.arch") + "\" is unknown")); + throw (CantLoadLibrary) new CantLoadLibrary().initCause(new IllegalStateException("Arch: \"" + System.getProperty("os.arch") + "\" is unknown")); } if (os == Os.unknown) { - throw new CantLoadLibrary().initCause(new IllegalStateException("Os: \"" + System.getProperty("os.name") + "\" is unknown")); + throw (CantLoadLibrary) new CantLoadLibrary().initCause(new IllegalStateException("Os: \"" + System.getProperty("os.name") + "\" is unknown")); } try { @@ -82,7 +82,7 @@ public class LoadLibrary { if (loadSysLibrary(libname)) { return; } - throw new CantLoadLibrary().initCause(e); + throw (CantLoadLibrary) new CantLoadLibrary().initCause(e); } }