Search in sources :

Example 1 with Path

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);
}
Also used : Path(com.teradata.jaqy.interfaces.Path)

Example 2 with Path

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());
}
Also used : Path(com.teradata.jaqy.interfaces.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStream(java.io.OutputStream) File(java.io.File) Test(org.junit.Test)

Example 3 with Path

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());
}
Also used : Path(com.teradata.jaqy.interfaces.Path) Test(org.junit.Test)

Example 4 with Path

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());
}
Also used : Path(com.teradata.jaqy.interfaces.Path) Test(org.junit.Test)

Example 5 with Path

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);
    }
}
Also used : Path(com.teradata.jaqy.interfaces.Path) CommandLine(org.apache.commons.cli.CommandLine) Reader(java.io.Reader) Option(org.apache.commons.cli.Option)

Aggregations

Path (com.teradata.jaqy.interfaces.Path)12 Test (org.junit.Test)4 Reader (java.io.Reader)3 CommandLine (org.apache.commons.cli.CommandLine)3 Option (org.apache.commons.cli.Option)3 CommandLineInput (com.teradata.jaqy.lineinput.CommandLineInput)2 JLineConsoleLineInput (com.teradata.jaqy.lineinput.JLineConsoleLineInput)2 FilePath (com.teradata.jaqy.path.FilePath)2 Session (com.teradata.jaqy.Session)1 LineInput (com.teradata.jaqy.interfaces.LineInput)1 ReaderLineInput (com.teradata.jaqy.lineinput.ReaderLineInput)1 FileBlob (com.teradata.jaqy.resultset.FileBlob)1 FileClob (com.teradata.jaqy.resultset.FileClob)1 CSVExportInfo (com.teradata.jaqy.utils.CSVExportInfo)1 CSVImportInfo (com.teradata.jaqy.utils.CSVImportInfo)1 CSVNameGen (com.teradata.jaqy.utils.CSVNameGen)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1