Browse Source
Added MD5 hashing to HashService and ImageHashDTO. Added tests against MD5 hashes. Added library for digests and hashing. Added Engine and test against Engine
master
Added MD5 hashing to HashService and ImageHashDTO. Added tests against MD5 hashes. Added library for digests and hashing. Added Engine and test against Engine
master
Drew Short
11 years ago
11 changed files with 266 additions and 39 deletions
-
5pom.xml
-
31src/main/scala/com/sothr/imagetools/Engine.scala
-
11src/main/scala/com/sothr/imagetools/dto/ImageHashDTO.scala
-
77src/main/scala/com/sothr/imagetools/hash/HashService.scala
-
30src/main/scala/com/sothr/imagetools/image/Image.scala
-
18src/main/scala/com/sothr/imagetools/image/ImageFilter.scala
-
15src/main/scala/com/sothr/imagetools/image/ImageService.scala
-
14src/main/scala/com/sothr/imagetools/util/Version.scala
-
11src/test/scala/com/sothr/imagetools/EngineTest.scala
-
54src/test/scala/com/sothr/imagetools/hash/HashServiceTest.scala
-
31src/test/scala/com/sothr/imagetools/image/ImageFilterTest.scala
@ -0,0 +1,31 @@ |
|||||
|
package com.sothr.imagetools |
||||
|
|
||||
|
import com.sothr.imagetools.image.{ImageFilter, Image} |
||||
|
import scala.collection.immutable |
||||
|
import scala.collection.mutable |
||||
|
import java.io.File |
||||
|
import grizzled.slf4j.Logging |
||||
|
|
||||
|
/** |
||||
|
* Created by drew on 1/26/14. |
||||
|
*/ |
||||
|
class Engine extends Logging{ |
||||
|
|
||||
|
val imageFilter:ImageFilter = new ImageFilter() |
||||
|
|
||||
|
def getImagesForDirectory(directoryPath:String):List[Image] = { |
||||
|
val images:mutable.MutableList[Image] = new mutable.MutableList[Image]() |
||||
|
val directory:File = new File(directoryPath) |
||||
|
if (directory.isDirectory) { |
||||
|
val files = directory.listFiles(imageFilter) |
||||
|
debug(s"Found ${files.length} files that are images in directory: $directoryPath") |
||||
|
for (file <- files) { |
||||
|
images += ImageService.getImage(file) |
||||
|
} |
||||
|
} else { |
||||
|
error(s"Provided path: $directoryPath is not a directory") |
||||
|
} |
||||
|
images.toList |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
package com.sothr.imagetools.image |
||||
|
|
||||
|
import java.io.{File, FilenameFilter} |
||||
|
import scala.collection.immutable.HashSet |
||||
|
|
||||
|
/** |
||||
|
* Created by drew on 1/26/14. |
||||
|
*/ |
||||
|
class ImageFilter extends FilenameFilter { |
||||
|
|
||||
|
private val extensions:HashSet[String] = new HashSet[String]() ++ Array("png", "bmp", "gif", "jpg", "jpeg") |
||||
|
|
||||
|
def accept(dir: File, name: String): Boolean = { |
||||
|
val splitName = name.split('.') |
||||
|
val extension = if (splitName.length > 1) splitName(splitName.length-1) else "" |
||||
|
if (extensions.contains(extension)) true else false |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
package com.sothr.imagetools |
||||
|
|
||||
|
/** |
||||
|
* Created by drew on 1/26/14. |
||||
|
*/ |
||||
|
class EngineTest extends BaseTest{ |
||||
|
test("Test getImagesForDirectory for sample directory") { |
||||
|
val engine:Engine = new Engine() |
||||
|
assertResult(3) { engine.getImagesForDirectory("sample").length } |
||||
|
} |
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
package com.sothr.imagetools.image |
||||
|
|
||||
|
import com.sothr.imagetools.BaseTest |
||||
|
import java.io.File |
||||
|
|
||||
|
/** |
||||
|
* Created by drew on 1/26/14. |
||||
|
*/ |
||||
|
class ImageFilterTest extends BaseTest{ |
||||
|
|
||||
|
test("Confirm ImageFilter Works") { |
||||
|
val filter:ImageFilter = new ImageFilter() |
||||
|
val bogusDirectory = new File(".") |
||||
|
assert(filter.accept(bogusDirectory, "test.png")) |
||||
|
assert(filter.accept(bogusDirectory, "test.bmp")) |
||||
|
assert(filter.accept(bogusDirectory, "test.gif")) |
||||
|
assert(filter.accept(bogusDirectory, "test.jpg")) |
||||
|
assert(filter.accept(bogusDirectory, "test.jpeg")) |
||||
|
assert(filter.accept(bogusDirectory, "test.jpeg.jpg")) |
||||
|
} |
||||
|
|
||||
|
test("Confirm ImageFiler Fails") { |
||||
|
val filter:ImageFilter = new ImageFilter() |
||||
|
val bogusDirectory = new File(".") |
||||
|
assertResult(false) { filter.accept(bogusDirectory,"test") } |
||||
|
assertResult(false) { filter.accept(bogusDirectory,"test.mp4") } |
||||
|
assertResult(false) { filter.accept(bogusDirectory,"test.gif.mp4") } |
||||
|
assertResult(false) { filter.accept(bogusDirectory,"") } |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue