Skip to content

Commit ab594a8

Browse files
committed
Refactored code so it's no longer turbo ugly
1 parent 142de58 commit ab594a8

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

.idea/workspace.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/com/barney/image/ImageInfo.kt

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,18 @@ import java.io.*
55
and https://jaimonmathew.wordpress.com/2011/01/29/simpleimageinfo/) rewritten in Kotlin.
66
* */
77

8-
class ImageInfo {
8+
class ImageInfo(file: File?) {
99
var height = 0
1010
var width = 0
1111
var mimeType: String? = null
1212

13-
private constructor() {}
14-
constructor(file: File?) {
15-
val `is`: InputStream = FileInputStream(file)
16-
`is`.use {`is` ->
17-
processStream(`is`)
13+
init {
14+
val stream: InputStream = FileInputStream(file!!)
15+
stream.use { inputStream ->
16+
processStream(inputStream)
1817
}
1918
}
2019

21-
constructor(`is`: InputStream) {
22-
processStream(`is`)
23-
}
24-
25-
constructor(bytes: ByteArray?) {
26-
val `is`: InputStream = ByteArrayInputStream(bytes)
27-
`is`.use { `is` ->
28-
processStream(`is`)
29-
}
30-
}
3120

3221
@Throws(IOException::class)
3322
private fun processStream(IS: InputStream) {
@@ -72,14 +61,13 @@ class ImageInfo {
7261
val c4 = IS.read()
7362
if ((c1 == 'M'.code && c2 == 'M'.code && c3 == 0 && c4 == 42) || (c1 == 'I'.code && c2 == 'I'.code && c3 == 42 && c4 == 0)) { //TIFF
7463
val bigEndian = c1 == 'M'.code
75-
var ifd = 0
76-
ifd = readInt(IS, 4, bigEndian)
64+
val ifd: Int = readInt(IS, 4, bigEndian)
7765
IS.skip((ifd - 8).toLong())
7866
val entries: Int = readInt(IS, 2, bigEndian)
7967
for (i in 1..entries) {
8068
val tag = readInt(IS, 2, bigEndian)
8169
val fieldType = readInt(IS, 2, bigEndian)
82-
val count = readInt(IS, 4, bigEndian).toLong()
70+
readInt(IS, 4, bigEndian).toLong()
8371
var valOffset: Int
8472
if (fieldType == 3 || fieldType == 8) {
8573
valOffset = readInt(IS, 2, bigEndian)

src/main/kotlin/main.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ fun main() {
1717
val path = File(System.getProperty("user.dir"))
1818
val files = path.listFiles()
1919
val fileTypes = setOf("png", "jpg", "jpeg", "gif", "tiff", "bmp")
20-
if(countFiles(input=files, types=fileTypes)==0) println("Make sure this file is in the same folder as your images.")
20+
if(countFiles(input= files!!, types=fileTypes)==0) println("Make sure this file is in the same folder as your images.")
2121
else {
2222
moveOrNot()
2323
for (i in files.indices) {
2424
if ((files[i].isFile) and (files[i].extension in fileTypes)) {
25-
var x = aspectRatio(files[i])
25+
val x = aspectRatio(files[i])
2626
when {
2727
(0.9f <= x) and (x <= 1.1f) -> {
2828
checkDirMove(dirname = "Square", input = files[i])
@@ -41,7 +41,7 @@ fun main() {
4141
Info.ultraWide++
4242
}
4343
}
44-
if (Info.moveBool == true) println("Moved " + files[i])
44+
if (Info.moveBool) println("Moved " + files[i])
4545
else println("Copied" + files[i])
4646
}
4747
}

0 commit comments

Comments
 (0)