<commit_before>package com.codeski.nbt;

import java.awt.GraphicsEnvironment;
import java.io.Console;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import com.codeski.nbt.tags.NBTCompound;

public class Main
{
	public static void main(String[] args) throws FileNotFoundException, IOException
	{
		Console console = System.console();
		if (console != null)
			if (args.length == 2) {
				// Read in a user specified file...
				File in = new File(args[0]);
				System.out.println("Reading " + in.getCanonicalPath() + "...");
				NBTCompound root = new NBTReader(in).read();
				// Write the file to NBT, JSON, or XML...
				File out = new File(args[1]);
				String extension = args[1].substring(args[1].lastIndexOf('.') + 1);
				System.out.println("Writing " + out.getCanonicalPath() + "...");
				NBTWriter nw = new NBTWriter(out);
				if (extension.equalsIgnoreCase("dat"))
					nw.writeNBT(root);
				else if (extension.equalsIgnoreCase("json"))
					nw.writeJSON(root);
				else if (extension.equalsIgnoreCase("xml"))
					nw.writeXML(root);
				else
					System.out.println("Cannot write file... Supported file extensions are dat, json, and xml.");
			} else
				System.out.println("Usage: java -jar " + new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName() + " <file-to-read> <file-to-write>");
		else if (!GraphicsEnvironment.isHeadless()) {
			JFileChooser fc = new JFileChooser();
			FileFilter nbt = new FileNameExtensionFilter("Named Binary Tag (.dat)", "dat");
			fc.addChoosableFileFilter(nbt);
			int ret = fc.showOpenDialog(null);
			if (ret == JFileChooser.APPROVE_OPTION) {
				File in = fc.getSelectedFile();
				NBTCompound root = new NBTReader(in).read();
				FileFilter json = new FileNameExtensionFilter("JavaScript Object Notation (.json)", "json");
				fc.addChoosableFileFilter(json);
				FileFilter xml = new FileNameExtensionFilter("Extensible Markup Language (.xml)", "xml");
				fc.addChoosableFileFilter(xml);
				fc.setFileFilter(fc.getAcceptAllFileFilter());
				ret = fc.showSaveDialog(null);
				if (ret == JFileChooser.APPROVE_OPTION) {
					File out = fc.getSelectedFile();
					NBTWriter nw = new NBTWriter(out);
					if (fc.getFileFilter().equals(nbt))
						nw.writeNBT(root);
					else if (fc.getFileFilter().equals(json))
						nw.writeJSON(root);
					else if (fc.getFileFilter().equals(xml))<commit_msg>Make default file type for writing file in CLI<commit_after>package com.codeski.nbt;

import java.awt.GraphicsEnvironment;
import java.io.Console;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import com.codeski.nbt.tags.NBTCompound;

public class Main
{
	public static void main(String[] args) throws FileNotFoundException, IOException
	{
		Console console = System.console();
		if (console != null)
			if (args.length == 2) {
				// Read in a user specified file...
				File in = new File(args[0]);
				System.out.println("Reading " + in.getCanonicalPath() + "...");
				NBTCompound root = new NBTReader(in).read();
				// Write the file to NBT, JSON, or XML...
				File out = new File(args[1]);
				String extension = args[1].substring(args[1].lastIndexOf('.') + 1);
				System.out.println("Writing " + out.getCanonicalPath() + "...");
				NBTWriter nw = new NBTWriter(out);
				if (extension.equalsIgnoreCase("dat"))
					nw.writeNBT(root);
				else if (extension.equalsIgnoreCase("json"))
					nw.writeJSON(root);
				else if (extension.equalsIgnoreCase("xml"))
					nw.writeXML(root);
				else {
					System.out.println("File extension was not dat, json, or xml. Writing NBT by default.");
					nw.writeNBT(root);
				}
			} else
				System.out.println("Usage: java -jar " + new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName() + " <file-to-read> <file-to-write>");
		else if (!GraphicsEnvironment.isHeadless()) {
			JFileChooser fc = new JFileChooser();
			FileFilter nbt = new FileNameExtensionFilter("Named Binary Tag (.dat)", "dat");
			fc.addChoosableFileFilter(nbt);
			int ret = fc.showOpenDialog(null);
			if (ret == JFileChooser.APPROVE_OPTION) {
				File in = fc.getSelectedFile();
				NBTCompound root = new NBTReader(in).read();
				FileFilter json = new FileNameExtensionFilter("JavaScript Object Notation (.json)", "json");
				fc.addChoosableFileFilter(json);
				FileFilter xml = new FileNameExtensionFilter("Extensible Markup Language (.xml)", "xml");
				fc.addChoosableFileFilter(xml);
				fc.setFileFilter(fc.getAcceptAllFileFilter());
				ret = fc.showSaveDialog(null);
				if (ret == JFileChooser.APPROVE_OPTION) {
					File out = fc.getSelectedFile();
					NBTWriter nw = new NBTWriter(out);
					if (fc.getFileFilter().equals(nbt))
						nw.writeNBT(root);
					else if (fc.getFileFilter().equals(json))
						nw.writeJSON(root);
					else if (fc.getFileFilter().equals(xml))
{'fraction_non_alphanumeric': 0.14401544401544403, 'fraction_numerical': 0.0023166023166023165, 'mean_word_length': 4.044790652385589, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3298863', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1649, 'n_words': 367}