Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Java.nio' - 6 code snippet(s) found

 Sample 1. Apache Kafka Consumer

https://apache.googlesource.com/kafka/+/trunk/examples/src/main/java/kafka/examples/Consumer.java?autodive=0%2F

   Like      Feedback     


 Sample 2. Apache Hadoop Map Reduce Example

https://apache.googlesource.com/hadoop-common/+/trunk/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/Grep.java

   Like      Feedback     


 Sample 3. Usage of org.apache.hadoop.fs.Trash , org.apache.hive.spark.client.rpc.RPC,java.nio.file.FileSystem

private void initialize(String address, Configuration conf) throws IOException {
   InetSocketAddress socAddr = NameNode.getAddress(address);
   this.supportAppends = conf.getBoolean("dfs.support.append", true);
   this.handlerCount = conf.getInt("dfs.namenode.handler.count", 10);
   this.server = RPC.getServer(this, socAddr.getHostName(), socAddr.getPort(),handlerCount, false, conf);

   this.nameNodeAddress = this.server.getListenerAddress();
   FileSystem.setDefaultUri(conf, getUri(nameNodeAddress));
   LOG.info("Namenode up at: " + this.nameNodeAddress);

   myMetrics = new NameNodeMetrics(conf, this);

   this.namesystem = new FSNamesystem(this, conf);
   this.server.start(); //start RPC server

   this.emptier = new Thread(new Trash(conf).getEmptier(), "Trash Emptier");
   this.emptier.setDaemon(true);
   this.emptier.start();
}

   Like      Feedback     


 Sample 4. Usage of java.nio.channels.FileLock

File lockF = new File(root, STORAGE_FILE_LOCK);
lockF.deleteOnExit();
RandomAccessFile file = new RandomAccessFile(lockF, "rws");
FileLock res = null;
try {
   res = file.getChannel().tryLock();
} catch(OverlappingFileLockException oe) {

}

   Like      Feedback     java.nio  FileLock  input output  file handling


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Bitwise comparison of objects , compareTo Implementation

public int compareTo(Object other) {
   Buffer right = ((Buffer) other);
   byte[] lb = this.get();
   byte[] rb = right.get();
   for (int i = 0; i < count && i < right.count; i++) {
      int a = (lb[i] & 0xff);
      int b = (rb[i] & 0xff);
      if (a != b) {
         return a - b;
      }
   }
   return count - right.count;
}

   Like      Feedback     compareTo  java.nio.Buffer


 Sample 6. Code Sample / Example / Snippet of java.nio.channels.FileChannel

    public static void copy(File input, File output) throws IOException {

FileInputStream fis = new FileInputStream(input);

FileOutputStream fos = new FileOutputStream(output);



try {

FileChannel ic = fis.getChannel();

FileChannel oc = fos.getChannel();

try {

oc.transferFrom(ic, 0, ic.size());

}

finally {

oc.close();

ic.close();

}

}

finally {

fis.close();

fos.close();

}

}


   Like      Feedback      java.nio.channels.FileChannel



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner