This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
import javax.management.*; | |
import java.lang.management.ManagementFactory; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.concurrent.atomic.AtomicLong; | |
/** | |
* Created by daniel on 06/07/2015. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
import java.io.EOFException; | |
import java.io.IOException; | |
import java.net.InetSocketAddress; | |
import java.nio.ByteBuffer; | |
import java.nio.ByteOrder; | |
import java.nio.channels.ServerSocketChannel; | |
import java.nio.channels.SocketChannel; | |
import java.util.Arrays; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
import javax.naming.Context; | |
import javax.naming.NamingEnumeration; | |
import javax.naming.NamingException; | |
import javax.naming.directory.*; | |
import java.text.MessageFormat; | |
import java.util.*; | |
public class ADConnect { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
import java.util.Random; | |
import java.util.stream.IntStream; | |
public class RandomString { | |
public static void main(String[] args) { | |
Random random = new Random(); | |
IntStream.range(0,10). | |
forEach(i->System.out.println(generateRandomString(random, 9))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
try { | |
//Write with compression | |
//COMPILES BUT SO UGLY | |
writeToFile(new File("test"), "Hello World", i -> { | |
try { | |
return new GZIPOutputStream(i); | |
} catch (IOException e) { | |
//HOW ARE WE SUPPOSED TO DEAL WITH THIS EXCEPTION?? | |
throw new AssertionError(e); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
try { | |
//Write with compression | |
//DOES NOT COMPILE!! | |
writeToFile(new File("test"), "Hello World", GZIPOutputStream::new); | |
//Just use the FileOutputStream | |
writeToFile(new File("test"), "Hello World", i->i); | |
}catch(IOException e){ | |
//deal with exception as you choose | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void writeToFile(File file, String value, | |
Function<OutputStream, OutputStream> writing) throws IOException{ | |
try (PrintWriter pw = new PrintWriter(new BufferedOutputStream | |
(writing.apply(new FileOutputStream(file))))) { | |
pw.write(value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
import java.io.*; | |
import java.util.zip.GZIPOutputStream; | |
public class LambdaExceptions { | |
public static void main(String[] args) { | |
try { | |
//Write with compression | |
writeToFile(new File("test"), "Hello World", GZIPOutputStream::new); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
public class Allocation2 { | |
static int iterations = 10_000_000; | |
public static void main(String[] args) { | |
for (int i = 0; i <3 ; i++) { | |
testNoAllocations(); | |
testAllocations(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
public class Allocation1 { | |
static int iterations = 10_000_000; | |
public static void main(String[] args) { | |
for (int i = 0; i <3 ; i++) { | |
testNoAllocations(); | |
testAllocations(); | |
} |