daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Dec 9th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.math.*;
  3. import java.net.*;
  4. import java.nio.file.*;
  5. import java.util.*;
  6. import java.util.concurrent.*;
  7. import java.util.function.*;
  8. import java.util.prefs.*;
  9. import java.util.regex.*;
  10. import java.util.stream.*;
  11.  
  12. class BsonToJson{
  13.   public static void main(String[] args){
  14.     Scanner scanner = new Scanner(System.in);
  15.     Pattern pd = Pattern.compile(".*ISODate\\((\\S*)\\).*");
  16.     Pattern po = Pattern.compile(".*ObjectId\\((\\S*)\\).*");
  17.     Pattern pl = Pattern.compile(".*NumberLong\\((\\S*)\\).*");
  18.     // Read and print out each line.
  19.     while (scanner.hasNextLine()) {
  20.       String lineOfInput = scanner.nextLine();
  21.  
  22.       Matcher md =  pd.matcher(lineOfInput);
  23.       Matcher mo = po.matcher(lineOfInput);
  24.       Matcher ml = pl.matcher(lineOfInput);
  25.  
  26.       String ret = md.matches() ? lineOfInput.replace("ISODate("+ md.group(1) + ")", md.group(1)) : lineOfInput;
  27.  
  28.       ret = mo.matches() ? lineOfInput.replace("ObjectId("+ mo.group(1) + ")", mo.group(1)) :ret;
  29.       ret = ml.matches() ? lineOfInput.replace("NumberLong("+ ml.group(1) + ")", ml.group(1)) :ret;
  30.  
  31.       System.out.println(ret);
  32.     }
  33.   }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top