1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.java;
  27 
  28 import java.io.File;
  29 import java.io.InputStream;
  30 import java.io.FileInputStream;
  31 import java.io.IOException;
  32 
  33 /**
  34  * This class is used to represent a file loaded from the class path, and
  35  * is a regular file.
  36  *
  37  * WARNING: The contents of this source file are not part of any
  38  * supported API.  Code that depends on them does so at its own risk:
  39  * they are subject to change or removal without notice.
  40  */
  41 final
  42 class FileClassFile extends ClassFile {
  43     private final File file;
  44 
  45     /**
  46      * Constructor for instance representing a regular file
  47      */
  48     public FileClassFile(File file) {
  49         this.file = file;
  50     }
  51 
  52     @Override
  53     public boolean isZipped() {
  54         return false;
  55     }
  56 
  57     @Override
  58     public InputStream getInputStream() throws IOException {
  59         return new FileInputStream(file);
  60     }
  61 
  62     @Override
  63     public boolean exists() {
  64         return file.exists();
  65     }
  66 
  67     @Override
  68     public boolean isDirectory() {
  69         return file.isDirectory();
  70     }
  71 
  72     @Override
  73     public long lastModified() {
  74         return file.lastModified();
  75     }
  76 
  77     @Override
  78     public String getPath() {
  79         return file.getPath();
  80     }
  81 
  82     @Override
  83     public String getName() {
  84         return file.getName();
  85     }
  86 
  87 //JCOV
  88     @Override
  89     public String getAbsoluteName() {
  90         String absoluteName;
  91         try {
  92             absoluteName = file.getCanonicalPath();
  93         } catch (IOException e) {
  94             absoluteName = file.getAbsolutePath();
  95         }
  96         return absoluteName;
  97     }
  98 // end JCOV
  99 
 100     @Override
 101     public long length() {
 102         return file.length();
 103     }
 104 
 105     @Override
 106     public String toString() {
 107         return file.toString();
 108     }
 109 }