Skip to content

Commit

Permalink
Applied after review fixes and fixed typos. Adjusted access scope for…
Browse files Browse the repository at this point in the history
… definitions
  • Loading branch information
WojciechMazur committed Jun 2, 2021
1 parent a6115f4 commit cd05441
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
7 changes: 2 additions & 5 deletions javalib/src/main/scala/java/io/File.scala
Expand Up @@ -21,8 +21,8 @@ import scala.scalanative.windows
import windows.FileApi._
import windows.FileApiExt._
import scala.scalanative.windows.WinBaseApi._
import scala.scalanative.windows.util.HelperMethods._
import scala.scalanative.windows.winnt.AccessRights._
import java.util.WindowsHelperMethods._

class File(_path: String) extends Serializable with Comparable[File] {
import File._
Expand Down Expand Up @@ -372,10 +372,7 @@ class File(_path: String) extends Serializable with Comparable[File] {

// Ported from Apache Harmony
def toURI(): URI = {
val path = getAbsolutePath().map {
case '\\' => '/'
case c => c
}
val path = getAbsolutePath().replace('\\', '/')
if (!path.startsWith("/")) {
// start with sep.
new URI(
Expand Down
2 changes: 1 addition & 1 deletion javalib/src/main/scala/java/io/FileOutputStream.scala
Expand Up @@ -14,7 +14,7 @@ import scala.scalanative.windows.FileApiExt._
import scala.scalanative.windows.HandleApiExt._
import scala.scalanative.windows.winnt.AccessRights._

class FileOutputStream(fd: FileDescriptor, file: Option[File] = None)
class FileOutputStream(fd: FileDescriptor, file: Option[File])
extends OutputStream {
def this(fd: FileDescriptor) = this(fd, None)
def this(file: File, append: Boolean) =
Expand Down
Expand Up @@ -221,6 +221,7 @@ private[net] abstract class AbstractPlainSocketImpl extends SocketImpl {
if (!isClosed) {
fd.close()
fd = InvalidSocketDescriptor
isClosed = true
}
}

Expand Down Expand Up @@ -456,7 +457,7 @@ private[net] abstract class AbstractPlainSocketImpl extends SocketImpl {
}
}

object AbstractPlainSocketImpl {
private[net] object AbstractPlainSocketImpl {
final val InvalidSocketDescriptor = new FileDescriptor

def apply(): AbstractPlainSocketImpl = {
Expand Down
24 changes: 13 additions & 11 deletions javalib/src/main/scala/scala/scalanative/nio/fs/FileHelpers.scala
Expand Up @@ -18,7 +18,7 @@ import scala.scalanative.windows.FileApi._
import scala.scalanative.windows.FileApiExt._
import scala.scalanative.windows.HandleApiExt._
import scala.scalanative.windows.winnt.AccessRights._
import scala.scalanative.windows.util.HelperMethods._
import scala.scalanative.windows._

object FileHelpers {
private[this] lazy val random = new scala.util.Random()
Expand Down Expand Up @@ -62,17 +62,19 @@ object FileHelpers {
} else
Zone { implicit z =>
if (isWindows) {
withFileOpen(
path,
access = FILE_GENERIC_WRITE,
val handle = CreateFileW(
toCWideStringUTF16LE(path),
desiredAccess = FILE_GENERIC_WRITE,
shareMode = FILE_SHARE_ALL,
disposition = CREATE_NEW,
allowInvalidHandle = true
) { handle =>
GetLastError() match {
case ErrorCodes.ERROR_FILE_EXISTS => false
case _ => handle != INVALID_HANDLE_VALUE
}
securityAttributes = null,
creationDisposition = CREATE_NEW,
flagsAndAttributes = FILE_ATTRIBUTE_NORMAL,
templateFile = null
)
HandleApi.CloseHandle(handle)
GetLastError() match {
case ErrorCodes.ERROR_FILE_EXISTS => false
case _ => handle != INVALID_HANDLE_VALUE
}
} else {
fopen(toCString(path), c"w") match {
Expand Down
Expand Up @@ -3,10 +3,10 @@ package scala.scalanative.windows.util
import scala.scalanative.unsigned._
import scala.scalanative.windows.{Word => WinWord}

object Conversion {
private[windows] object Conversion {
def wordToBytes(word: WinWord): (Byte, Byte) = {
val lowByte = (word & 0xFF.toUShort).toByte
val highByte = (word >> 8 & 0xFF.toUShort).toByte
val lowByte = (word.toInt & 0xFF).toByte
val highByte = ((word.toInt >> 8) & 0xFF).toByte
(lowByte, highByte)
}

Expand Down

0 comments on commit cd05441

Please sign in to comment.