diff --git a/build.gradle b/build.gradle index caac0f0..afe620e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,79 @@ -project.group = "org.telegram" - -def basicVersion = '1.0' -if (project.hasProperty('buildIndex')) { - project.version = basicVersion + '.' + project.buildIndex -} else { - project.version = basicVersion + '-SNAPSHOT' +buildscript { + repositories { + mavenCentral() + } +} +repositories { + mavenCentral() } apply plugin: 'java' -apply plugin: 'maven' \ No newline at end of file +apply plugin: 'maven' +apply plugin: 'signing' + +group = 'org.telegram-s' +version = '1.1.0' + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from 'build/docs/javadoc' +} + +task sourcesJar(type: Jar) { + from sourceSets.main.allSource + classifier = 'sources' +} + +artifacts { + archives jar + + archives javadocJar + archives sourcesJar +} + +if (project.hasProperty("ossrhUsername") && project.hasProperty("ossrhPassword")) { + + signing { + sign configurations.archives + } + + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + pom.project { + name 'Telegram TL' + packaging 'jar' + description 'Telegram TL library for TL serialization' + url 'https://github.com/telegram-s/telegram-tl' + + scm { + url 'scm:git@github.com:telegram-s/telegram-tl.git' + connection 'scm:git@github.com:telegram-s/telegram-tl.git' + developerConnection 'scm:git@github.com:telegram-s/telegram-tl.git' + } + + licenses { + license { + name 'The MIT License (MIT)' + url 'http://opensource.org/licenses/MIT' + distribution 'repo' + } + } + + developers { + developer { + id 'ex3ndr' + name 'Stepan Korshakov' + } + } + } + } + } + } +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..b761216 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..6d2d1d4 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Aug 28 20:42:47 GST 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/org/telegram/tl/DeserializeException.java b/src/main/java/org/telegram/tl/DeserializeException.java index 39f5a38..64a55f0 100644 --- a/src/main/java/org/telegram/tl/DeserializeException.java +++ b/src/main/java/org/telegram/tl/DeserializeException.java @@ -3,10 +3,9 @@ import java.io.IOException; /** - * Created with IntelliJ IDEA. - * User: ex3ndr - * Date: 02.11.13 - * Time: 6:52 + * Exception while deserizalization + * + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class DeserializeException extends IOException { public DeserializeException() { diff --git a/src/main/java/org/telegram/tl/RequestExecutor.java b/src/main/java/org/telegram/tl/RequestExecutor.java index 49a070e..4af3582 100644 --- a/src/main/java/org/telegram/tl/RequestExecutor.java +++ b/src/main/java/org/telegram/tl/RequestExecutor.java @@ -4,6 +4,8 @@ /** * Basic class of rpc method index class + * + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ @Deprecated public abstract class RequestExecutor { diff --git a/src/main/java/org/telegram/tl/StreamingUtils.java b/src/main/java/org/telegram/tl/StreamingUtils.java index 6fda154..cf4fdb7 100644 --- a/src/main/java/org/telegram/tl/StreamingUtils.java +++ b/src/main/java/org/telegram/tl/StreamingUtils.java @@ -7,7 +7,7 @@ /** * Helper class for writing and reading data for tl (de-)serialization. * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class StreamingUtils { @@ -16,7 +16,7 @@ public class StreamingUtils { * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeByte(int v, OutputStream stream) throws IOException { stream.write(v); @@ -27,7 +27,7 @@ public static void writeByte(int v, OutputStream stream) throws IOException { * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeByte(byte v, OutputStream stream) throws IOException { stream.write(v); @@ -38,7 +38,7 @@ public static void writeByte(byte v, OutputStream stream) throws IOException { * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeInt(int v, OutputStream stream) throws IOException { writeByte((byte) (v & 0xFF), stream); @@ -52,7 +52,7 @@ public static void writeInt(int v, OutputStream stream) throws IOException { * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeLong(long v, OutputStream stream) throws IOException { writeByte((byte) (v & 0xFF), stream); @@ -71,7 +71,7 @@ public static void writeLong(long v, OutputStream stream) throws IOException { * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeDouble(double v, OutputStream stream) throws IOException { writeLong(Double.doubleToLongBits(v), stream); @@ -82,7 +82,7 @@ public static void writeDouble(double v, OutputStream stream) throws IOException * * @param data data * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeByteArray(byte[] data, OutputStream stream) throws IOException { stream.write(data); @@ -92,8 +92,10 @@ public static void writeByteArray(byte[] data, OutputStream stream) throws IOExc * Writing byte array to stream * * @param data data + * @param offset offset in array + * @param len byte count * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeByteArray(byte[] data, int offset, int len, OutputStream stream) throws IOException { stream.write(data, offset, len); @@ -104,7 +106,7 @@ public static void writeByteArray(byte[] data, int offset, int len, OutputStream * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeTLBool(boolean v, OutputStream stream) throws IOException { if (v) { @@ -119,7 +121,7 @@ public static void writeTLBool(boolean v, OutputStream stream) throws IOExceptio * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeTLString(String v, OutputStream stream) throws IOException { writeTLBytes(v.getBytes(), stream); @@ -130,7 +132,7 @@ public static void writeTLString(String v, OutputStream stream) throws IOExcepti * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeTLBytes(byte[] v, OutputStream stream) throws IOException { int startOffset = 1; @@ -158,7 +160,7 @@ public static void writeTLBytes(byte[] v, OutputStream stream) throws IOExceptio * * @param v value * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeTLBytes(TLBytes v, OutputStream stream) throws IOException { int startOffset = 1; @@ -186,7 +188,7 @@ public static void writeTLBytes(TLBytes v, OutputStream stream) throws IOExcepti * * @param v tl-object * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeTLObject(TLObject v, OutputStream stream) throws IOException { v.serialize(stream); @@ -197,7 +199,7 @@ public static void writeTLObject(TLObject v, OutputStream stream) throws IOExcep * * @param v tl-method * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeTLMethod(TLMethod v, OutputStream stream) throws IOException { writeTLObject(v, stream); @@ -208,7 +210,7 @@ public static void writeTLMethod(TLMethod v, OutputStream stream) throws IOExcep * * @param v tl-vector * @param stream destination stream - * @throws IOException + * @throws IOException IO Exception */ public static void writeTLVector(TLVector v, OutputStream stream) throws IOException { writeTLObject(v, stream); @@ -219,7 +221,7 @@ public static void writeTLVector(TLVector v, OutputStream stream) throws IOExcep * * @param stream source stream * @return value - * @throws IOException reading exception + * @throws IOException IO Exception */ public static int readInt(InputStream stream) throws IOException { int a = stream.read(); @@ -247,7 +249,7 @@ public static int readInt(InputStream stream) throws IOException { * * @param stream source stream * @return value - * @throws IOException reading exception + * @throws IOException IO Exception */ public static long readUInt(InputStream stream) throws IOException { long a = stream.read(); @@ -275,7 +277,7 @@ public static long readUInt(InputStream stream) throws IOException { * * @param stream source stream * @return value - * @throws IOException reading exception + * @throws IOException IO Exception */ public static long readLong(InputStream stream) throws IOException { long a = readUInt(stream); @@ -289,7 +291,7 @@ public static long readLong(InputStream stream) throws IOException { * * @param stream source stream * @return value - * @throws IOException reading exception + * @throws IOException IO Exception */ public static double readDouble(InputStream stream) throws IOException { return Double.longBitsToDouble(readLong(stream)); @@ -300,7 +302,7 @@ public static double readDouble(InputStream stream) throws IOException { * * @param stream source stream * @return value - * @throws IOException reading exception + * @throws IOException IO Exception */ public static String readTLString(InputStream stream) throws IOException { return new String(readTLBytes(stream)); @@ -312,7 +314,7 @@ public static String readTLString(InputStream stream) throws IOException { * @param stream source stream * @param context tl-context * @return tl-object - * @throws IOException reading exception + * @throws IOException IO Exception */ public static TLObject readTLObject(InputStream stream, TLContext context) throws IOException { return context.deserializeMessage(stream); @@ -324,7 +326,7 @@ public static TLObject readTLObject(InputStream stream, TLContext context) throw * @param stream source stream * @param context tl-method * @return tl-method - * @throws IOException reading exception + * @throws IOException IO Exception */ public static TLMethod readTLMethod(InputStream stream, TLContext context) throws IOException { return (TLMethod) context.deserializeMessage(stream); @@ -335,8 +337,8 @@ public static TLMethod readTLMethod(InputStream stream, TLContext context) throw * * @param count bytes count * @param stream source stream - * @return readed bytes - * @throws IOException reading exception + * @return read bytes + * @throws IOException IO Exception */ public static byte[] readBytes(int count, InputStream stream) throws IOException { byte[] res = new byte[count]; @@ -359,8 +361,7 @@ public static byte[] readBytes(int count, InputStream stream) throws IOException * * @param count bytes count * @param stream source stream - * @return readed bytes - * @throws IOException reading exception + * @throws IOException IO Exception */ public static void skipBytes(int count, InputStream stream) throws IOException { stream.skip(count); @@ -369,10 +370,11 @@ public static void skipBytes(int count, InputStream stream) throws IOException { /** * Reading bytes from stream * + * @param buffer source data + * @param offset offset in array * @param count bytes count * @param stream source stream - * @return readed bytes - * @throws IOException reading exception + * @throws IOException IO Exception */ public static void readBytes(byte[] buffer, int offset, int count, InputStream stream) throws IOException { int woffset = 0; @@ -392,8 +394,8 @@ public static void readBytes(byte[] buffer, int offset, int count, InputStream s * Reading tl-bytes from stream * * @param stream source stream - * @return readed bytes - * @throws IOException reading exception + * @return read bytes + * @throws IOException IO Exception */ public static byte[] readTLBytes(InputStream stream) throws IOException { int count = stream.read(); @@ -418,8 +420,8 @@ public static byte[] readTLBytes(InputStream stream) throws IOException { * * @param stream source stream * @param context tl-context - * @return readed bytes - * @throws IOException reading exception + * @return read bytes + * @throws IOException rIO Exception */ public static TLBytes readTLBytes(InputStream stream, TLContext context) throws IOException { int count = stream.read(); @@ -445,7 +447,7 @@ public static TLBytes readTLBytes(InputStream stream, TLContext context) throws * @param stream source stream * @param context tl-context * @return tl-vector - * @throws IOException reading exception + * @throws IOException IO Exception */ public static TLVector readTLVector(InputStream stream, TLContext context) throws IOException { return context.deserializeVector(stream); @@ -457,7 +459,7 @@ public static TLVector readTLVector(InputStream stream, TLContext context) throw * @param stream source stream * @param context tl-context * @return tl-vector of integers - * @throws IOException reading exception + * @throws IOException IO Exception */ public static TLIntVector readTLIntVector(InputStream stream, TLContext context) throws IOException { return context.deserializeIntVector(stream); @@ -469,7 +471,7 @@ public static TLIntVector readTLIntVector(InputStream stream, TLContext context) * @param stream source stream * @param context tl-context * @return tl-vector of longs - * @throws IOException reading exception + * @throws IOException IO Exception */ public static TLLongVector readTLLongVector(InputStream stream, TLContext context) throws IOException { return context.deserializeLongVector(stream); @@ -481,7 +483,7 @@ public static TLLongVector readTLLongVector(InputStream stream, TLContext contex * @param stream source stream * @param context tl-context * @return tl-vector of strings - * @throws IOException reading exception + * @throws IOException IO Exception */ public static TLStringVector readTLStringVector(InputStream stream, TLContext context) throws IOException { return context.deserializeStringVector(stream); @@ -492,7 +494,7 @@ public static TLStringVector readTLStringVector(InputStream stream, TLContext co * * @param stream source stream * @return bool - * @throws IOException reading exception + * @throws IOException IO Exception */ public static boolean readTLBool(InputStream stream) throws IOException { int v = readInt(stream); diff --git a/src/main/java/org/telegram/tl/TLBool.java b/src/main/java/org/telegram/tl/TLBool.java index 0199ccc..23c6376 100644 --- a/src/main/java/org/telegram/tl/TLBool.java +++ b/src/main/java/org/telegram/tl/TLBool.java @@ -3,7 +3,7 @@ /** * Packed type of tl-bool * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public abstract class TLBool extends TLObject { } diff --git a/src/main/java/org/telegram/tl/TLBoolFalse.java b/src/main/java/org/telegram/tl/TLBoolFalse.java index 1a0d540..c21da4f 100644 --- a/src/main/java/org/telegram/tl/TLBoolFalse.java +++ b/src/main/java/org/telegram/tl/TLBoolFalse.java @@ -3,7 +3,7 @@ /** * Packed type of tl-bool false value * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class TLBoolFalse extends TLBool { diff --git a/src/main/java/org/telegram/tl/TLBoolTrue.java b/src/main/java/org/telegram/tl/TLBoolTrue.java index b56c982..18bdb3a 100644 --- a/src/main/java/org/telegram/tl/TLBoolTrue.java +++ b/src/main/java/org/telegram/tl/TLBoolTrue.java @@ -3,7 +3,7 @@ /** * Packed type of tl-bool true value * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class TLBoolTrue extends TLBool { diff --git a/src/main/java/org/telegram/tl/TLBytes.java b/src/main/java/org/telegram/tl/TLBytes.java index a27b8cc..cc70ecd 100644 --- a/src/main/java/org/telegram/tl/TLBytes.java +++ b/src/main/java/org/telegram/tl/TLBytes.java @@ -1,9 +1,9 @@ package org.telegram.tl; -import java.util.Arrays; - /** - * Created by ex3ndr on 10.02.14. + * TL Bytes + * + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class TLBytes { private byte[] data; diff --git a/src/main/java/org/telegram/tl/TLContext.java b/src/main/java/org/telegram/tl/TLContext.java index 728c690..ebcd9cf 100644 --- a/src/main/java/org/telegram/tl/TLContext.java +++ b/src/main/java/org/telegram/tl/TLContext.java @@ -15,7 +15,7 @@ * but it uses reflection so it might be slow in some cases. It recommended to manually pass CLASS_ID * to registerClass method. * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public abstract class TLContext { private final HashMap registeredClasses = new HashMap(); @@ -25,18 +25,39 @@ public TLContext() { init(); } + /** + * Registering of all known classes might be here + */ protected void init() { } + /** + * Is object supported by this context + * + * @param object source object + * @return is object supported + */ public boolean isSupportedObject(TLObject object) { return isSupportedObject(object.getClassId()); } + /** + * Is class supported by this context + * + * @param classId class id + * @return is class supported + */ public boolean isSupportedObject(int classId) { return registeredClasses.containsKey(classId); } + /** + * Registering class for serialization + * + * @param tClass source class + * @param TLObject class + */ public void registerClass(Class tClass) { try { int classId = tClass.getField("CLASS_ID").getInt(null); @@ -48,10 +69,24 @@ public void registerClass(Class tClass) { } } + /** + * Registering class for serialization. It work faster than {@link org.telegram.tl.TLContext#registerClass(Class)} + * because it does not use reflection for class id. + * + * @param clazzId class id + * @param tClass source class + * @param TLObject class + */ public void registerClass(int clazzId, Class tClass) { registeredClasses.put(clazzId, tClass); } + /** + * Registering compatibility class + * + * @param tClass compat class + * @param TLObject class + */ public void registerCompatClass(Class tClass) { try { int classId = tClass.getField("CLASS_ID").getInt(null); @@ -63,18 +98,46 @@ public void registerCompatClass(Class tClass) { } } + /** + * Registering compatibility class + * + * @param clazzId compat class id + * @param tClass compat class + * @param TLObject class + */ public void registerCompatClass(int clazzId, Class tClass) { registeredCompatClasses.put(clazzId, tClass); } + /** + * Override for providing compatibility between old classes and current scheme + * + * @param src compat object + * @return new object + */ protected TLObject convertCompatClass(TLObject src) { return src; } + /** + * Deserializing message from bytes + * + * @param data message bytes + * @return result + * @throws IOException reading exception + */ public TLObject deserializeMessage(byte[] data) throws IOException { return deserializeMessage(new ByteArrayInputStream(data)); } + /** + * Deserializing message from stream + * + * @param clazzId class id + * @param stream source stream + * @return result + * @throws IOException reading exception + */ public TLObject deserializeMessage(int clazzId, InputStream stream) throws IOException { if (clazzId == TLGzipObject.CLASS_ID) { TLGzipObject obj = new TLGzipObject(); @@ -123,11 +186,25 @@ public TLObject deserializeMessage(int clazzId, InputStream stream) throws IOExc } } + /** + * Deserializing message from stream + * + * @param stream source stream + * @return result + * @throws IOException reading exception + */ public TLObject deserializeMessage(InputStream stream) throws IOException { int clazzId = StreamingUtils.readInt(stream); return deserializeMessage(clazzId, stream); } + /** + * Deserializing object vector + * + * @param stream source stream + * @return result + * @throws IOException reading exception + */ public TLVector deserializeVector(InputStream stream) throws IOException { int clazzId = StreamingUtils.readInt(stream); if (clazzId == TLVector.CLASS_ID) { @@ -144,6 +221,13 @@ public TLVector deserializeVector(InputStream stream) throws IOException { } } + /** + * Deserializing int vector + * + * @param stream source stream + * @return result + * @throws IOException reading exception + */ public TLIntVector deserializeIntVector(InputStream stream) throws IOException { int clazzId = StreamingUtils.readInt(stream); if (clazzId == TLVector.CLASS_ID) { @@ -160,6 +244,13 @@ public TLIntVector deserializeIntVector(InputStream stream) throws IOException { } } + /** + * Deserializing long vector + * + * @param stream source stream + * @return result + * @throws IOException reading exception + */ public TLLongVector deserializeLongVector(InputStream stream) throws IOException { int clazzId = StreamingUtils.readInt(stream); if (clazzId == TLVector.CLASS_ID) { @@ -176,6 +267,13 @@ public TLLongVector deserializeLongVector(InputStream stream) throws IOException } } + /** + * Deserializing string vector + * + * @param stream source stream + * @return result + * @throws IOException reading exception + */ public TLStringVector deserializeStringVector(InputStream stream) throws IOException { int clazzId = StreamingUtils.readInt(stream); if (clazzId == TLVector.CLASS_ID) { @@ -192,10 +290,21 @@ public TLStringVector deserializeStringVector(InputStream stream) throws IOExcep } } + /** + * Allocating TLBytes object. Override for providing memory usage optimizations + * + * @param size required minimum size of data + * @return allocated TLBytes + */ public TLBytes allocateBytes(int size) { return new TLBytes(new byte[size], 0, size); } + /** + * Releasing unused TLBytes for reuse in allocation + * + * @param unused unused TLBytes + */ public void releaseBytes(TLBytes unused) { } diff --git a/src/main/java/org/telegram/tl/TLGzipObject.java b/src/main/java/org/telegram/tl/TLGzipObject.java index b868955..8e784db 100644 --- a/src/main/java/org/telegram/tl/TLGzipObject.java +++ b/src/main/java/org/telegram/tl/TLGzipObject.java @@ -10,30 +10,40 @@ /** * Basic class of gzipped object * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class TLGzipObject extends TLObject { public static final int CLASS_ID = 0x3072CFA1; - @Override - public int getClassId() { - return CLASS_ID; + private byte[] packedData; + + public TLGzipObject() { + } public TLGzipObject(byte[] packedData) { this.packedData = packedData; } - public TLGzipObject() { - + @Override + public int getClassId() { + return CLASS_ID; } - private byte[] packedData; - + /** + * Getting gzipped content + * + * @return GZipped content + */ public byte[] getPackedData() { return packedData; } + /** + * Setting packed content + * + * @param packedData gzipped content + */ public void setPackedData(byte[] packedData) { this.packedData = packedData; } diff --git a/src/main/java/org/telegram/tl/TLIntVector.java b/src/main/java/org/telegram/tl/TLIntVector.java index 6a8bfa7..608e777 100644 --- a/src/main/java/org/telegram/tl/TLIntVector.java +++ b/src/main/java/org/telegram/tl/TLIntVector.java @@ -1,9 +1,9 @@ package org.telegram.tl; /** - * TL Vector of integers. @see org.telegram.tl.TLVector + * TL Vector of integers. {@link org.telegram.tl.TLVector} * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class TLIntVector extends TLVector { public TLIntVector() { @@ -15,6 +15,11 @@ public String toString() { return "vector#1cb5c415"; } + /** + * Converting vector to int array + * + * @return int array + */ public int[] toIntArray() { int[] res = new int[size()]; for (int i = 0; i < res.length; i++) { diff --git a/src/main/java/org/telegram/tl/TLLongVector.java b/src/main/java/org/telegram/tl/TLLongVector.java index 1dcb8cc..051bfec 100644 --- a/src/main/java/org/telegram/tl/TLLongVector.java +++ b/src/main/java/org/telegram/tl/TLLongVector.java @@ -1,9 +1,9 @@ package org.telegram.tl; /** - * TL Vector of longs. @see org.telegram.tl.TLVector + * TL Vector of longs. {@link org.telegram.tl.TLVector} * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class TLLongVector extends TLVector { public TLLongVector() { diff --git a/src/main/java/org/telegram/tl/TLMethod.java b/src/main/java/org/telegram/tl/TLMethod.java index d0ab4d5..cf3ff36 100644 --- a/src/main/java/org/telegram/tl/TLMethod.java +++ b/src/main/java/org/telegram/tl/TLMethod.java @@ -8,12 +8,28 @@ * Basic object for RPC methods. It contains special methods for deserializing result of RPC method call. * * @param return type of method - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public abstract class TLMethod extends TLObject { + /** + * Deserialization of method response + * + * @param data data response + * @param context tl context + * @return deserialized response + * @throws IOException reading exceptions + */ public T deserializeResponse(byte[] data, TLContext context) throws IOException { return deserializeResponse(new ByteArrayInputStream(data), context); } + /** + * Deserialization of method response + * + * @param stream source stream + * @param context tl context + * @return deserizlied response + * @throws IOException reading exceptions + */ public abstract T deserializeResponse(InputStream stream, TLContext context) throws IOException; } diff --git a/src/main/java/org/telegram/tl/TLObject.java b/src/main/java/org/telegram/tl/TLObject.java index fed2823..5b07a34 100644 --- a/src/main/java/org/telegram/tl/TLObject.java +++ b/src/main/java/org/telegram/tl/TLObject.java @@ -5,14 +5,13 @@ import static org.telegram.tl.StreamingUtils.*; /** - * Basic class for all tl-objects. Contains methods for serializing and deserializing object. + *

Basic class for all tl-objects. Contains methods for serializing and deserializing object. * Each tl-object has class id for using in object header for identifying object class for deserialization. - * This number might be unique and often equals to crc32 of tl-record of tl-constructor. - *

+ * This number might be unique and often equals to crc32 of tl-record of tl-constructor.

* It is recommended to declare public static final CLASS_ID with tl class id and * return this in getClassId and passing it to TLContext.registerClass method during class registration * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public abstract class TLObject implements Serializable { @@ -27,7 +26,7 @@ public abstract class TLObject implements Serializable { * Serializing object to byte array * * @return serialized object with header - * @throws IOException + * @throws IOException writing exception */ public byte[] serialize() throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -39,7 +38,7 @@ public byte[] serialize() throws IOException { * Serializing object to stream * * @param stream destination stream - * @throws IOException + * @throws IOException writing exception */ public void serialize(OutputStream stream) throws IOException { writeInt(getClassId(), stream); @@ -51,7 +50,7 @@ public void serialize(OutputStream stream) throws IOException { * * @param stream source stream * @param context tl context - * @throws IOException + * @throws IOException reading exception */ public void deserialize(InputStream stream, TLContext context) throws IOException { int classId = readInt(stream); @@ -66,7 +65,7 @@ public void deserialize(InputStream stream, TLContext context) throws IOExceptio * Serializing object body to stream * * @param stream destination stream - * @throws IOException + * @throws IOException writing exception */ public void serializeBody(OutputStream stream) throws IOException { @@ -77,7 +76,7 @@ public void serializeBody(OutputStream stream) throws IOException { * * @param stream source stream * @param context tl context - * @throws IOException + * @throws IOException reading exception */ public void deserializeBody(InputStream stream, TLContext context) throws IOException { diff --git a/src/main/java/org/telegram/tl/TLStringVector.java b/src/main/java/org/telegram/tl/TLStringVector.java index 58f3e88..27fcaf1 100644 --- a/src/main/java/org/telegram/tl/TLStringVector.java +++ b/src/main/java/org/telegram/tl/TLStringVector.java @@ -1,9 +1,9 @@ package org.telegram.tl; /** - * TL Vector of strings. @see org.telegram.tl.TLVector + * TL Vector of strings. {@link org.telegram.tl.TLVector} * - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class TLStringVector extends TLVector { public TLStringVector() { diff --git a/src/main/java/org/telegram/tl/TLVector.java b/src/main/java/org/telegram/tl/TLVector.java index 31d930c..c6da622 100644 --- a/src/main/java/org/telegram/tl/TLVector.java +++ b/src/main/java/org/telegram/tl/TLVector.java @@ -13,7 +13,7 @@ * vector of integer, strings or long. * * @param type of elements in vector - * @author Korshakov Stepan + * @author Stepan Ex3NDR Korshakov (me@ex3ndr.com) */ public class TLVector extends TLObject implements List { @@ -27,10 +27,20 @@ public int getClassId() { return CLASS_ID; } + /** + * Vector content class + * + * @return content class + */ public Class getDestClass() { return destClass; } + /** + * Setting content class + * + * @param destClass content class + */ public void setDestClass(Class destClass) { if (destClass == null) { throw new RuntimeException("DestClass could not be null");