Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 124 add java nio path support #61

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -35,12 +35,12 @@ public MailcapRegistry getByFileName(String arg0) throws IOException {

@Override
public MailcapRegistry getByInputStream(InputStream arg0) throws IOException {
return null;
return new MyMailcapRegistry();
}

@Override
public MailcapRegistry getInMemory() {
return null;
return new MyMailcapRegistry();
}

private static class MyMailcapRegistry implements MailcapRegistry {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -34,12 +34,12 @@ public MimeTypeRegistry getByFileName(String arg0) throws IOException {

@Override
public MimeTypeRegistry getByInputStream(InputStream arg0) throws IOException {
return null;
return new MyMimeTypeRegistry();
}

@Override
public MimeTypeRegistry getInMemory() {
return null;
return new MyMimeTypeRegistry();
}

private static class MyMimeTypeRegistry implements MimeTypeRegistry {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -17,6 +17,9 @@
package javasoft.sqe.tests.jakarta.activation.FileDataSource;

import java.io.*;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;

import jakarta.activation.*;
import com.sun.javatest.*;
import com.sun.javatest.lib.MultiTest;
Expand Down Expand Up @@ -47,10 +50,13 @@ public Status FileDataSourceTest1()
{
FileDataSource fdsFromFile = new FileDataSource(new File(kFileName)); // API TEST
FileDataSource fdsFromFileName = new FileDataSource(kFileName); // API TEST
FileDataSource fdsFromPath = new FileDataSource(Paths.get(kFileName)); // API TEST
if (!kFileName.equals(fdsFromFileName.getName()))
return Status.failed("FileDataSource(fileName) nameTest failed");
if (!kFileName.equals(fdsFromFile.getName()))
return Status.failed("FileDataSource(File) nameTest failed");
if (!kFileName.equals(fdsFromPath.getName()))
return Status.failed("FileDataSource(Path) nameTest failed");

return Status.passed("FileDataSource() test passed");
}
Expand All @@ -63,7 +69,7 @@ public Status FileDataSourceTest2()
try {
is = lSource.getInputStream();
is.close();
} catch (FileNotFoundException fnfex) {
} catch (FileNotFoundException | NoSuchFileException fnfex) {
return Status.passed("FileDataSource() no input test passed");
} catch (Exception ex) {
return Status.failed("FileDataSource() no input test failed: unexpected exception " + ex.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -17,6 +17,8 @@
package javasoft.sqe.tests.jakarta.activation.FileDataSource;

import java.io.*;
import java.nio.file.Paths;

import jakarta.activation.*;
import com.sun.javatest.*;
import com.sun.javatest.lib.MultiTest;
Expand All @@ -43,13 +45,17 @@ public Status getFileTest()
{
FileDataSource fdsFromFile = new FileDataSource(new File(kFileName));
FileDataSource fdsFromFileName = new FileDataSource(kFileName);
FileDataSource fdsFromPath = new FileDataSource(Paths.get(kFileName));
File fob1 = fdsFromFile.getFile(); // API TEST
File fob2 = fdsFromFileName.getFile(); // API TEST
File fob3 = fdsFromPath.getFile(); // API TEST

if( fob1 == null )
return Status.failed("getFile() test failed");
return Status.failed("getFile() from FileDataSource(File) test failed");
if( fob2 == null )
return Status.failed("getFile() test failed");
return Status.failed("getFile() from FileDataSource(String) test failed");
if( fob3 == null )
return Status.failed("getFile() from FileDataSource(Path) test failed");

return Status.passed("getFile() test passed");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -17,10 +17,12 @@
package javasoft.sqe.tests.jakarta.activation.FileDataSource;

import java.io.*;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;

import jakarta.activation.*;
import com.sun.javatest.*;
import com.sun.javatest.lib.MultiTest;
import javasoft.sqe.tests.jakarta.activation.TestClasses.TestFileTypeMap;

/**
* Create an instance of FileDataSource, use it to invoke getInputStream()
Expand All @@ -45,8 +47,9 @@ public Status getInputStreamTest1()
{
FileDataSource fdsFromFile = new FileDataSource(new File(kFileName));
FileDataSource fdsFromFileName = new FileDataSource(kFileName);
boolean lPassed = true;
message = "ioTest succeeded";
FileDataSource fdsFromPath = new FileDataSource(Paths.get(kFileName));

message = "ioTest succeeded";

msgPrefix = "FileDataSource(File) ";
if (!testIO(fdsFromFile))
Expand All @@ -56,6 +59,10 @@ public Status getInputStreamTest1()
if (!testIO(fdsFromFileName))
return Status.failed(msgPrefix + message);

msgPrefix = "FileDataSource(Path) ";
if (!testIO(fdsFromPath))
return Status.failed(msgPrefix + message);

return Status.passed("getInputStream() " + message);
}

Expand All @@ -67,7 +74,7 @@ public Status getInputStreamTest2()
try {
is = lSource.getInputStream(); // API TEST
is.close();
} catch (FileNotFoundException fnfex) {
} catch (FileNotFoundException | NoSuchFileException fnfex) {
return Status.passed("getInputStream() test passed");
} catch (Exception ex) {
return Status.failed("Failed: unexpected exception " + ex.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -17,6 +17,8 @@
package javasoft.sqe.tests.jakarta.activation.FileDataSource;

import java.io.*;
import java.nio.file.Paths;

import jakarta.activation.*;
import com.sun.javatest.*;
import com.sun.javatest.lib.MultiTest;
Expand All @@ -43,13 +45,17 @@ public Status getNameTest()
{
FileDataSource fdsFromFile = new FileDataSource(new File(kFileName));
FileDataSource fdsFromFileName = new FileDataSource(kFileName);
FileDataSource fdsFromPath = new FileDataSource(Paths.get(kFileName));
String name1 = fdsFromFile.getName(); // API TEST
String name2 = fdsFromFileName.getName(); // API TEST
String name3 = fdsFromPath.getName(); // API TEST

if( name1 == null )
return Status.failed("getName() test failed");
return Status.failed("getName() from FileDataSource(File) test failed");
if( name2 == null )
return Status.failed("getName() test failed");
return Status.failed("getName() from FileDataSource(String) test failed");
if( name3 == null )
return Status.failed("getName() from FileDataSource(Path) test failed");

return Status.passed("getName() test passed");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -17,10 +17,11 @@
package javasoft.sqe.tests.jakarta.activation.FileDataSource;

import java.io.*;
import java.nio.file.Paths;

import jakarta.activation.*;
import com.sun.javatest.*;
import com.sun.javatest.lib.MultiTest;
import javasoft.sqe.tests.jakarta.activation.TestClasses.TestFileTypeMap;

/**
* Create an instance of FileDataSource, use it to invoke getOutputStream()
Expand All @@ -45,6 +46,7 @@ public Status getOutputStreamTest1()
{
FileDataSource fdsFromFile = new FileDataSource(new File(kFileName));
FileDataSource fdsFromFileName = new FileDataSource(kFileName);
FileDataSource fdsFromPath = new FileDataSource(Paths.get(kFileName));
boolean lPassed = true;
message = "ioTest succeeded";

Expand All @@ -56,6 +58,10 @@ public Status getOutputStreamTest1()
if (!testIO(fdsFromFileName))
return Status.failed(msgPrefix + message);

msgPrefix = "FileDataSource(Path) ";
if (!testIO(fdsFromPath))
return Status.failed(msgPrefix + message);

return Status.passed("getOutputStream() " + message);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -17,6 +17,8 @@
package javasoft.sqe.tests.jakarta.activation.FileTypeMap;

import java.io.*;
import java.nio.file.Paths;

import jakarta.activation.*;
import com.sun.javatest.*;
import javasoft.sqe.tests.jakarta.activation.TestClasses.TestFileTypeMap;
Expand All @@ -31,6 +33,8 @@
public class getContentType_Test implements Test
{

private static final String TESTFILE_NAME = "testfile.txt";

public static void main(String argv[])
{
getContentType_Test lTest = new getContentType_Test();
Expand All @@ -40,17 +44,22 @@ public static void main(String argv[])

public Status run(String argv[], PrintWriter outLog, PrintWriter outConsole)
{
File fob = new File("testfile.txt");
File fob = new File(TESTFILE_NAME);
FileTypeMap ftm = FileTypeMap.getDefaultFileTypeMap();
String content1 = ftm.getContentType(fob); // API TEST

if( content1 == null )
return Status.failed("getContentType() returned null");
return Status.failed("getContentType() with File returned null");

String content2 = ftm.getContentType("testfile.txt"); // API TEST
String content2 = ftm.getContentType(TESTFILE_NAME); // API TEST

if( content2 == null )
return Status.failed("getContentType() returned null");
return Status.failed("getContentType() with String returned null");

String content3 = ftm.getContentType(Paths.get(TESTFILE_NAME)); // API TEST

if( content3 == null )
return Status.failed("getContentType() with Path returned null");

return Status.passed("getContentType() test succeeded");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -17,6 +17,8 @@
package javasoft.sqe.tests.jakarta.activation.MimetypesFileTypeMap;

import java.io.*;
import java.nio.file.Paths;

import jakarta.activation.*;
import com.sun.javatest.*;
import com.sun.javatest.lib.MultiTest;
Expand Down Expand Up @@ -78,6 +80,12 @@ private String validateType(String fName, String expectedType)
message = "getContentType(File) returned " + res2 + " should be " + res1;
return res1;
}

String res3 = typesMap.getContentType(Paths.get(fName)); // API TEST
if(!res1.equals(res3)) {
message = "getContentType(Path) returned " + res3 + " should be " + res1;
return res1;
}
return res1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package javasoft.sqe.tests.jakarta.activation.TestClasses;

import java.io.*;
import java.nio.file.Path;

import jakarta.activation.*;

/** Test utility library used by FileTypeMap tests.
Expand All @@ -35,4 +37,9 @@ public String getContentType(File f) {
public String getContentType(String filename){
return getTestType();
}

@Override
public String getContentType(Path path) {
return getTestType();
}
}