We have a readily-available File-based implementation, reuse it instead
of rolling our own.
JIRA: YANGTOOLS-1275
Change-Id: I0a6604b83cb1aa216e61f5f5be97f93d2d1dd0e4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
* @param file Backing File
* @return A new YangTextSchemaSource
* @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file
* @param file Backing File
* @return A new YangTextSchemaSource
* @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file
- * @throws NullPointerException if file is null
+ * @throws NullPointerException if file is {@code null}
*/
public static @NonNull YangTextSchemaSource forFile(final File file) {
*/
public static @NonNull YangTextSchemaSource forFile(final File file) {
+ return forFile(file, identifierFromFilename(file.getName()));
+ }
+
+ /**
+ * Create a new YangTextSchemaSource backed by a {@link File} and specified {@link SourceIdentifier}.
+ *
+ * @param file Backing File
+ * @param identifier source identifier
+ * @return A new YangTextSchemaSource
+ * @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static @NonNull YangTextSchemaSource forFile(final File file, final SourceIdentifier identifier) {
checkArgument(file.isFile(), "Supplied file %s is not a file", file);
checkArgument(file.isFile(), "Supplied file %s is not a file", file);
- return new YangTextFileSchemaSource(identifierFromFilename(file.getName()), file);
+ return new YangTextFileSchemaSource(identifier, file);
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
-import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.util.concurrent.FluentFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.File;
import com.google.common.util.concurrent.FluentFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.File;
@Override
public YangTextSchemaSource restoreAsType(final SourceIdentifier sourceIdentifier, final File cachedSource) {
@Override
public YangTextSchemaSource restoreAsType(final SourceIdentifier sourceIdentifier, final File cachedSource) {
- return new YangTextSchemaSource(sourceIdentifier) {
-
- @Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return toStringHelper;
- }
-
- @Override
- public InputStream openStream() throws IOException {
- return Files.newInputStream(cachedSource.toPath());
- }
- };
+ return YangTextSchemaSource.forFile(cachedSource, sourceIdentifier);