use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.
the class AvroImporterFactory method getHandler.
@Override
public AvroImporter getHandler(CommandLine cmdLine, JaqyInterpreter interpreter) throws Exception {
String[] args = cmdLine.getArgs();
if (args.length == 0)
throw new IllegalArgumentException("missing file name.");
Path file = interpreter.getPath(args[0]);
return new AvroImporter(interpreter.getSession().getConnection(), file);
}
use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.
the class FilePathTest method test1.
@Test
public void test1() throws Exception {
FilePathHandler handler = new FilePathHandler();
File file = testFolder.newFile();
Path path;
path = handler.getPath(file.getAbsolutePath(), null);
Assert.assertNotNull(path);
OutputStream os = path.getOutputStream();
String str = "abcdefghijklmnopqrstuvwxyz";
os.write(str.getBytes("UTF-8"));
os.close();
Assert.assertEquals(file.getPath(), path.getPath());
Assert.assertEquals(file.getCanonicalPath(), path.getCanonicalPath());
Assert.assertTrue(path.exists());
Assert.assertTrue(path.isFile());
Assert.assertEquals(str.length(), path.length());
Assert.assertEquals(0, FileUtils.compare(new ByteArrayInputStream(str.getBytes("UTF-8")), path.getInputStream()));
path = path.getParent();
Assert.assertNotNull(path);
Assert.assertTrue(path.exists());
Assert.assertFalse(path.isFile());
path = path.getRelativePath(File.separator + "tmp");
Assert.assertEquals(File.separator + "tmp", path.getCanonicalPath());
}
use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.
the class HttpPathHandlerTest method test1.
@Test
public void test1() throws Exception {
HttpPathHandler handler = new HttpPathHandler();
String url = "http://introcs.cs.princeton.edu/java/data/DJIA.csv";
Assert.assertTrue(handler.canHandle(url));
Assert.assertTrue(handler.canHandle("https://introcs.cs.princeton.edu/java/data/DJIA.csv"));
Assert.assertFalse(handler.canHandle("C:\\abc"));
Assert.assertFalse(handler.canHandle("C:\\temp\\abc"));
Assert.assertFalse(handler.canHandle("/tmp/abc"));
Path path = handler.getPath(url, null);
Assert.assertEquals(url, path.getPath());
}
use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.
the class URLPathTest method test1.
@Test
public void test1() throws Exception {
HttpPathHandler handler = new HttpPathHandler();
String url = "https://introcs.cs.princeton.edu/java/data/DJIA.csv";
String parent = "https://introcs.cs.princeton.edu/java/data";
Path path = handler.getPath(url, null);
Assert.assertNotNull(path);
Assert.assertEquals(url, path.getPath());
Assert.assertEquals(url, path.getCanonicalPath());
Assert.assertTrue(path.exists());
Assert.assertEquals(1071673, path.length());
Assert.assertEquals(1071673, path.length());
Assert.assertTrue(path.isFile());
path = path.getParent();
Assert.assertEquals(parent, path.getPath());
path = path.getRelativePath("elements.csv");
Assert.assertTrue(path.isFile());
path = path.getParent();
path = path.getRelativePath("/java/data/DJIA.csv");
Assert.assertEquals(url, path.getPath());
path = path.getParent();
path = path.getRelativePath("../../java/data/DJIA.csv");
Assert.assertEquals(url, path.getPath());
path = path.getParent();
path = path.getRelativePath("../../java/data/abcdefghijklmnopqrstuvw.csv");
Assert.assertFalse(path.exists());
Assert.assertFalse(path.exists());
}
use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.
the class ScriptCommand method execute.
@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws Exception {
ScriptOptions scriptOptions = new ScriptOptions();
CommandLine cmdLine = getCommandLine(args);
args = cmdLine.getArgs();
for (Option option : cmdLine.getOptions()) {
switch(option.getOpt().charAt(0)) {
case 'c':
scriptOptions.encoding = option.getValue();
break;
}
}
String file = null;
if (args.length > 0)
file = args[0];
if (file == null) {
interpreter.setParseAction(this, scriptOptions);
} else {
Path scriptFile = interpreter.getPath(file);
if (!scriptFile.exists()) {
interpreter.error("file not found: " + file);
}
Reader reader = FileUtils.getReader(scriptFile.getInputStream(), scriptOptions.encoding);
interpreter.eval(reader);
}
}
Aggregations