Skip to content

Instantly share code, notes, and snippets.

View jinahya's full-sized avatar

Jin Kwon jinahya

  • Wemakeprice
  • Seoul, Korea
View GitHub Profile
public class WhiteByteChannel implements ReadableByteChannel {
@Override
public int read(final ByteBuffer dst) throws IOException {
final int remaining = dst.remaining();
dst.position(dst.limit());
return remaining;
}
@Override
public class BlackByteChannel implements WritableByteChannel {
@Override
public int write(final ByteBuffer src) throws IOException {
final int remainging = src.remaining();
src.position(src.limit());
return remainging;
}
@Override
public class FunnelInputStream extends FilterInputStream {
public FunnelInputStream(final InputStream in) {
super(in);
}
@Override
public int read(final byte[] b, final int off, final int len) throws IOExeption {
if (b == null) {
throw new NullPointerException("null b");
public class FunnelOutputStream extends FilterOutputStream {
public FunnelOutputStream(final OutputStream out) {
super(out);
}
}
public class CodeSnippetsInJavadoc {
/**
* Prints {@code hello, world\n} to {@code stdout}.
*
* <blockquote><pre>{@code
* public static void main(final String[] args) {
* System.out.printf("hello, world\n");
* }
* }</pre></blockquote>
@jinahya
jinahya / setup-x86_64.ps1
Last active November 19, 2015 22:35
updating cygwin installer itself and invoking it.
$file = "setup-x86_64.exe"
Invoke-WebRequest -OutFile $file https://www.cygwin.com/$file
Invoke-Expression .\$file
@jinahya
jinahya / pom.xml
Last active November 19, 2015 22:35
enforcing dependency convergence
<?xml version="1.0" encoding="utf-8"?>
<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>test</groupId>
<artifactId>enforcer-dependency-convergence-test</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
import java.nio.ByteBuffer;
import java.util.Arrays;
import static java.util.concurrent.ThreadLocalRandom.current;
public class ArrayWrappingByteBufferTest {
public static void main(final String[] args) {
final byte[] array = new byte[] {1, 1, 1, 1, 1, 1, 1, 1};
System.out.println("array: " + Arrays.toString(array));
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/beans_1_1.xsd">
</beans>
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Random;
import java.util.function.IntConsumer;
import java.util.function.IntSupplier;
/**
* Encodes/Decodes (maximum) 36-bit unsigned values.