|
Play Framework/Scala example source code file (Resources.scala)
The Resources.scala Play Framework example source code/* * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> */ package play.utils import java.net.{ URI, URL } import java.io.File import java.util.zip.ZipFile /** * Provide resources helpers */ object Resources { def isDirectory(url: URL) = url.getProtocol match { case "file" => new File(url.toURI).isDirectory case "jar" => isJarResourceDirectory(url) case _ => throw new IllegalArgumentException(s"Cannot check isDirectory for a URL with protocol='${url.getProtocol}'") } private def isJarResourceDirectory(url: URL): Boolean = { val path = url.getPath val bangIndex = url.getFile.indexOf("!") val jarFile: File = new File(URI.create(path.substring(0, bangIndex))) val resourcePath = URI.create(path.substring(bangIndex + 1)).getPath.drop(1) val zip = new ZipFile(jarFile) try { val entry = zip.getEntry(resourcePath) if (entry.isDirectory) true else { val stream = zip.getInputStream(entry) val isDir = stream == null if (stream != null) stream.close() isDir } } finally { zip.close() } } } Other Play Framework source code examplesHere is a short list of links related to this Play Framework Resources.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.