Skip to content

Commit

Permalink
Updated pom.xml and javadoc in order to publish in maven central repo…
Browse files Browse the repository at this point in the history
…sitory
  • Loading branch information
Sergiy Sevastyanov committed Nov 9, 2017
1 parent 2c65ff2 commit 9dfb2da
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 30 deletions.
177 changes: 151 additions & 26 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.snksoft</groupId>
<artifactId>java-crc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Generic CRC implementation for java</name>
<url>https://github.com/snksoft/java-crc</url>

<modelVersion>4.0.0</modelVersion>

<groupId>com.github.snksoft</groupId>
<artifactId>crc</artifactId>
<version>1.0.1</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
<description>Generic CRC implementation for java</description>
<url>https://github.com/snksoft/java-crc</url>

<licenses>
<license>
<name>BSD License</name>
<url>https://opensource.org/licenses/BSD-3-Clause</url>
</license>
</licenses>

<developers>
<developer>
<name>snksoft</name>
<organization>S&amp;K Software Development</organization>
<organizationUrl>https://github.com/snksoft</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:git://github.com/snksoft/java-crc.git</connection>
<developerConnection>scm:git:ssh://github.com:snksoft/java-crc.git</developerConnection>
<url>http://github.com/snksoft/java-crc/tree/master</url>
</scm>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -53,26 +86,118 @@
<skip>true</skip>
</configuration>
</plugin>

<!-- java doc plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<show>public</show>
<nohelp>true</nohelp>
</configuration>
</plugin>

<!-- maven deployment -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>

</plugins>
</build>

<dependencies>
<dependencies>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>

</dependencies>
</dependencies>

</project>
</project>

48 changes: 44 additions & 4 deletions src/main/java/com/github/snksoft/crc/CRC.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,50 @@
// A good list of parameter sets for various CRC algorithms can be found at http://reveng.sourceforge.net/crc-catalogue/.

/**
* This class provides utility functions for CRC calculation using either canonical straight forward approach
* or using "fast" table-driven implementation. Note, that even though table-driven implementation is much faster
* for processing large amounts of data and is commonly referred as fast algorithm, sometimes it might be quicker to
* calculate CRC using canonical algorithm then to prepare the table for table-driven implementation.
This class provides utility functions for CRC calculation using either canonical straight forward approach
or using "fast" table-driven implementation. Note, that even though table-driven implementation is much faster
for processing large amounts of data and is commonly referred as fast algorithm, sometimes it might be quicker to
calculate CRC using canonical algorithm then to prepare the table for table-driven implementation.
<p>
Using src is easy. Here is an example of calculating CCITT crc in one call using canonical approach.
<pre>
{@code
String data = "123456789";
long ccittCrc = CRC.calculateCRC(CRC.Parameters.CCITT, data.getBytes());
System.out.printf("CRC is 0x%04X\n", ccittCrc); // prints "CRC is 0x29B1"
}
</pre>
<p>
For larger data, table driven implementation is faster. Here is how to use it.
<pre>
{@code
String data = "123456789";
CRC tableDriven = new CRC(CRC.Parameters.XMODEM);
long xmodemCrc = tableDriven.calculateCRC(data.getBytes());
System.out.printf("CRC is 0x%04X\n", xmodemCrc); // prints "CRC is 0x31C3"
}
</pre>
<p>
You can also reuse CRC object instance for another crc calculation.
<p>
Given that the only state for a CRC calculation is the "intermediate value"
and it is stored in your code, you can even use same CRC instance to calculate CRC
of multiple data sets in parallel.
And if data is too big, you may feed it in chunks
<pre>
{@code
long curValue = tableDriven.init(); // initialize intermediate value
curValue = tableDriven.update(curValue, "123456789".getBytes()); // feed first chunk
curValue = tableDriven.update(curValue, "01234567890".getBytes()); // feed next chunk
long xmodemCrc2 = tableDriven.finalCRC(curValue); // gets CRC of whole data ("12345678901234567890")
System.out.printf("CRC is 0x%04X\n", xmodemCrc2); // prints "CRC is 0x2C89"
}
</pre>
* */
public class CRC
{
Expand Down

0 comments on commit 9dfb2da

Please sign in to comment.