A user would rarely wrap resources inside of a ManagedResource themselves. The following examples show how to use java.util.zip.GZIPInputStream.These examples are extracted from open source projects. Re: Scala Automatic Resource Management Incubator Project For production code I would also suggest to make sure that the source is closed again. They're actually mostly the same, it's just a matter of how you write the sample. There's no particular reason I chose my version besides that's how I wrote it.  The library actually would support your syntax (just with ManagedResource instead of managed). import scala.io.Source import scala.util.Try def niceFeedbackReadResource(resource: String): List[String] = Try(Source.fromResource(resource).getLines.toList) .recover(throw new FileNotFoundException(resource)) To get meaningful FNFEs instead. {FileOutputStream, InputStream, OutputStream} import java.io. Applications that are defining subclass of InputStream must provide method, returning the next byte of input. Re: Scala Automatic Resource Management Incubator Project GitHub Gist: instantly share code, notes, and snippets.
Hi, i'm Andrew , an Software Engineer in Test who loves to learn something new in coding and making machines do the routine work instead of me. For a user to get access to a Managed object, they'd have to use it inside a for-comprehension. In this case, the Handle is an InputStream and the Resource is a FileChannel. It represents input stream of bytes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. This is an excerpt from the Scala Cookbook (partially modified for the internet). Eventually, i found a nice and working way to load resources in scala : Source.fromInputStream(getClass().getClassLoader().getResourceAsStream("filename") That give's an InputStream which you can process then however you want. InputStreamReader(InputStream in_strm, Charset cs) : creates an InputStreamReader that uses the given charset. An example of where you would want a translated resource was FileChannels. However, if you need an opposite direction you are stuck, because there is no appropriate API in Scala … How to Convert scala.io.Source to InputStream Usually you convert Java's InputStream to Scala's Source and this kind of conversion is not a problem for an average Scala developer. InputStreamReader(InputStream in_strm) : Creates an InputStreamReader that uses the default charset.
I'm located in Amsterdam at the moment.My initial goal for my fabricator library that i'm working on is that it can be used in both Java and Scala projects. It was rather intended to be a library-writer's library.