Read just the version bytes from a las file.

<p>This can be handy is one needs to choose version reader.

@param lasFile the las file to check.
@return the version string as "major.minor" .
@throws IOException
420787
public static String getLasFileVersion( File lasFile ) throws IOException {
        FileInputStream fis = null;
        FileChannel fc = null;
        try {
            fis = new FileInputStream(lasFile);
            fc = fis.getChannel();
            // Version Major
            fis.skip(24);
            int versionMajor = fis.read();
            // Version Minor
            int versionMinor = fis.read();
            String version = versionMajor + "." + versionMinor; //$NON-NLS-1$
            return version;
        } finally {
            fc.close();
            fis.close();
        }
    }
505818
private FileStatus versionBasedGetFileInfo(String src) throws IOException {
    if (namenodeVersion >= ClientProtocol.OPTIMIZE_FILE_STATUS_VERSION) {
      return HdfsFileStatus.toFileStatus(namenode.getHdfsFileInfo(src), src);
    } else {
      return namenode.getFileInfo(src);
    }
  }
747013
public static String read(final File aFile) throws IOException {
        String string = new String(readBytes(aFile), StandardCharsets.UTF_8.name());

        if (string.endsWith(EOL)) {
            string = string.substring(0, string.length() - 1);
        }

        return string;
    }
483159
public static VersionMonitor getVersion(Class clazz) throws IOException {
        Manifest manifest = new Manifest();
        manifest.read(clazz.getResourceAsStream(MANIFEST_PATH));
        return getVersion(manifest);
    }
1078876
private static void printVersion() {

        System.out.println("jcheck_nrpe version " + JNRPEClient.class.getPackage().getImplementationVersion());
        System.out.println("Copyright (c) 2013 Massimiliano Ziccardi");
        System.out.println("Licensed under the Apache License, Version 2.0");
        System.out.println();
    }
1194584
public JavaClass readFromClassPath(String classFile)
    throws IOException
  {
    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();
    
    InputStream is = loader.getResourceAsStream(classFile);
    try {
      return parse(is);
    } finally {
      is.close();
    }
  }
766858
public void read(@WillClose InputStream inputStream) throws IOException {
        BufferedReader reader = new BufferedReader(Util.getReader(inputStream));

        int lineNumber = 0;
        try {
            String line;
            int lparen;
            String version;

            while ((line = reader.readLine()) != null) {
                ++lineNumber;

                if (lineNumber == 1) {
                    if (DEBUG) {
                        System.out.println("First line: " + line);
                    }
                    // Try to parse the version number string from the first
                    // line.
                    // null means that the line does not appear to be a version
                    // number.
                    version = parseVersionNumber(line);
                    if (version != null) {
                        // Check to see if version is supported.
                        // Only 1.0 supported for now.
                        if (!"1.0".equals(version)) {
                            throw new IOException("Unsupported sourceInfo version " + version);
                        }

                        // Version looks good. Skip to next line of file.
                        continue;
                    }
                }

                StringTokenizer tokenizer = new StringTokenizer(line, ",");

                String className = tokenizer.nextToken();
                String next = tokenizer.nextToken();
                if (DIGITS.matcher(next).matches()) {
                    // Line number for class
                    SourceLineRange range = createRange(next, tokenizer.nextToken());
                    classLineMap.put(className, range);
                    if (DEBUG) {
                        System.out.println("class:" + className + "," + range);
                    }
                } else if ((lparen = next.indexOf('(')) >= 0) {
                    // Line number for method
                    String methodName = next.substring(0, lparen);
                    String methodSignature = next.substring(lparen);

                    if ("init^".equals(methodName)) {
                        methodName = "<init>";
                    } else if ("clinit^".equals(methodName)) {
                        methodName = "<clinit>";
                    }

                    SourceLineRange range = createRange(tokenizer.nextToken(), tokenizer.nextToken());
                    methodLineMap.put(new MethodDescriptor(className, methodName, methodSignature), range);
                    if (DEBUG) {
                        System.out.println("method:" + methodName + methodSignature + "," + range);
                    }
                } else {
                    // Line number for field
                    String fieldName = next;
                    SourceLineRange range = createRange(tokenizer.nextToken(), tokenizer.nextToken());
                    fieldLineMap.put(new FieldDescriptor(className, fieldName), range);
                    if (DEBUG) {
                        System.out.println("field:" + className + "," + fieldName + "," + range);
                    }
                }

                // Note: we could complain if there are more tokens,
                // but instead we'll just ignore them.
            }
        } catch (NoSuchElementException e) {
            IOException ioe = new IOException("Invalid syntax in source info file at line " + lineNumber);
            ioe.initCause(e);
            throw ioe;
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
850417
@Override
  public String getVersion(URI uri) throws IOException
  {
    try {
      return StringUtils.format("%d", buildFileObject(uri, config).getLastModified());
    }
    catch (HdfsIOException ex) {
      throw ex.getIOException();
    }
  }
1259694
public static void logVersion(){
        String[] lines = {
            "Apache HTTPD & NGINX Access log parsing made easy",
            "For more information: https://github.com/nielsbasjes/logparser",
            "Copyright (C) 2011-2019 Niels Basjes - License Apache 2.0"
        };
        String version = getVersion();
        int width = version.length();
        for (String line: lines) {
            width = Math.max(width, line.length());
        }

        LOG.info("");
        LOG.info("/-{}-\\", padding('-', width));
        logLine(version, width);
        LOG.info("+-{}-+", padding('-', width));
        for (String line: lines) {
            logLine(line, width);
        }
        LOG.info("\\-{}-/", padding('-', width));
        LOG.info("");
    }
251649
static Map<String, String> getVersionAttributes(URL url) throws IOException {
        Map<String, String> ret = new LinkedHashMap<>();
        try (InputStream inputStream = url.openStream()) {
            Manifest manifest = new Manifest(inputStream);
            Attributes attributes = manifest.getMainAttributes();
            for (String key : VERSION_ATTRIBUTES) {
                final String value = attributes.getValue(key);
                ret.put(key, value == null ? UNKNOWN_VALUE : value);
            }
        }
        return ret;
    }
553023
protected String getVersion(JSONObject json, String fileName) {
        if (json.has(Constants.VERSION)) {
            return json.getString(Constants.VERSION);
        }
        logger.debug("version not found in file {}", fileName);
        return Constants.EMPTY_STRING;
    }
482330
def read_version():
    ""
    version_file = local_file('source', 'added_value', 'version.py')
    local_vars = {}
    with open(version_file) as handle:
        exec(handle.read(), {}, local_vars)  # pylint: disable=exec-used
    return local_vars['__version__']
292409
static String parseLastReleaseBuild(File mdFile, ProtocVersion protocVersion) throws IOException {
		int lastBuild = 0;
		try {
			DocumentBuilder xmlBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			Document xmlDoc = xmlBuilder.parse(mdFile);
			NodeList versions = xmlDoc.getElementsByTagName("version");
			for (int i = 0; i < versions.getLength(); i++) {
				Node ver = versions.item(i);
				String verStr = ver.getTextContent();
				if (verStr.startsWith(protocVersion.mVersion+"-build")) {
					String buildStr = verStr.substring(verStr.indexOf("-build")+"-build".length());
					int build = Integer.parseInt(buildStr);
					if (build > lastBuild) lastBuild = build;
				}
			}
		}
		catch (Exception e) {
			throw new IOException(e);
		}
		if (lastBuild > 0) return protocVersion.mVersion+"-build"+lastBuild;
		return null;
	}
265284
protected int loadLibraryFrom(
      String soName, int loadFlags, File libDir, StrictMode.ThreadPolicy threadPolicy)
      throws IOException {
    File soFile = new File(libDir, soName);
    if (!soFile.exists()) {
      Log.d(SoLoader.TAG, soName + " not found on " + libDir.getCanonicalPath());
      return LOAD_RESULT_NOT_FOUND;
    } else {
      Log.d(SoLoader.TAG, soName + " found on " + libDir.getCanonicalPath());
    }
    if ((loadFlags & LOAD_FLAG_ALLOW_IMPLICIT_PROVISION) != 0 &&
        (flags & ON_LD_LIBRARY_PATH) != 0) {
      Log.d(SoLoader.TAG, soName + " loaded implicitly");
      return LOAD_RESULT_IMPLICITLY_PROVIDED;
    }

    if ((flags & RESOLVE_DEPENDENCIES) != 0) {
      loadDependencies(soFile, loadFlags, threadPolicy);
    } else {
      Log.d(SoLoader.TAG, "Not resolving dependencies for " + soName);
    }

    try {
      SoLoader.sSoFileLoader.load(soFile.getAbsolutePath(), loadFlags);
    } catch (UnsatisfiedLinkError e) {
      if (e.getMessage().contains("bad ELF magic")) {
        Log.d(SoLoader.TAG, "Corrupted lib file detected");
        // Swallow exception. Higher layers will try again from a backup source
        return LOAD_RESULT_CORRUPTED_LIB_FILE;
      } else {
        throw e;
      }
    }

    return LOAD_RESULT_LOADED;
  }
759205
public static int getVersion(URI editsURI) throws IOException {
    if (editsURI.getScheme().equals(NNStorage.LOCAL_URI_SCHEME)) {
      StorageDirectory sd = new NNStorage(new StorageInfo()).new StorageDirectory(
          new File(editsURI.getPath()));
      File versionFile = sd.getVersionFile();
      if (!versionFile.exists()) {
        throw new IOException("No VERSION file in: " + editsURI + "version file: " + versionFile );
      }
      Properties props = Storage.getProps(versionFile);
      String layout = props.getProperty(Storage.LAYOUT_VERSION);
      if (layout == null) {
        throw new IOException("No layout version in: " + editsURI);
      }
      return Integer.valueOf(layout);
    } else {
      throw new IOException("Non file journals not supported yet.");
    }
  }
727372
private void readClassFile(ClassSymbol c) throws IOException {
        int magic = nextInt();
        if (magic != JAVA_MAGIC)
            throw badClassFile("illegal.start.of.class.file");

        minorVersion = nextChar();
        majorVersion = nextChar();
        int maxMajor = Target.MAX().majorVersion;
        int maxMinor = Target.MAX().minorVersion;
        if (majorVersion > maxMajor ||
            majorVersion * 1000 + minorVersion <
            Target.MIN().majorVersion * 1000 + Target.MIN().minorVersion)
        {
            if (majorVersion == (maxMajor + 1))
                log.warning("big.major.version",
                            currentClassFile,
                            majorVersion,
                            maxMajor);
            else
                throw badClassFile("wrong.version",
                                   Integer.toString(majorVersion),
                                   Integer.toString(minorVersion),
                                   Integer.toString(maxMajor),
                                   Integer.toString(maxMinor));
        }
        else if (checkClassFile &&
                 majorVersion == maxMajor &&
                 minorVersion > maxMinor)
        {
            printCCF("found.later.version",
                     Integer.toString(minorVersion));
        }
        indexPool();
        if (signatureBuffer.length < bp) {
            int ns = Integer.highestOneBit(bp) << 1;
            signatureBuffer = new byte[ns];
        }
        readClass(c);
    }
1340907
@Override
    public int read(char[] cbuf, int off, int len) throws IOException
    {
        if (m_stringReader == null) {
            m_bytes = m_jarFile.get(m_path);
            if (m_bytes == null) {
                // A stubborn caller will get StringReader exceptions.
                m_stringReader = new StringReader("");
                throw new IOException(String.format(
                        "DDL file \"%s\" not found in in-memory jar file.",
                        m_path));
            }
            m_stringReader = new StringReader(new String(m_bytes, "UTF-8"));
        }
        return m_stringReader.read(cbuf, off, len);
    }