本文整理汇总了Scala中java.lang.IllegalArgumentException类的典型用法代码示例。如果您正苦于以下问题:Scala IllegalArgumentException类的具体用法?Scala IllegalArgumentException怎么用?Scala IllegalArgumentException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IllegalArgumentException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Barcodes
//设置package包名称以及导入依赖的类
package controllers
import play.api.mvc.{Action, Controller}
class Barcodes extends Controller {
val ImageResolution = 144
// png? ???? Action
def barcode(ean: Long) = Action {
import java.lang.IllegalArgumentException
val MimeType = "image/png"
try {
val imageData = ean13BarCode(ean, MimeType)
Ok(imageData).as(MimeType)
}
catch {
case e: IllegalArgumentException =>
BadRequest("Couldn't generate bar code. Error: " + e.getMessage)
}
}
def ean13BarCode(ean: Long, mimeType: String): Array[Byte] = {
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.upcean.EAN13Bean
val output: ByteArrayOutputStream = new ByteArrayOutputStream
val canvas: BitmapCanvasProvider = new BitmapCanvasProvider(
output, mimeType, ImageResolution, BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barcode = new EAN13Bean()
barcode.generateBarcode(canvas, String valueOf ean)
canvas.finish
output.toByteArray
}
}
示例2: Converter
//设置package包名称以及导入依赖的类
package com.dataoptimo.imgprocessing.convert
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.io.Text
import org.apache.hadoop.io.BytesWritable
import org.apache.hadoop.fs.{Path, FileSystem}
import org.apache.hadoop.io.IOUtils
import org.apache.hadoop.io.SequenceFile
import java.io.IOException
import java.lang.IllegalArgumentException
class Converter(conf: Configuration) {
def imageToSequence(srcPath: String, dstPath: String){
try {
val fs = FileSystem.get(conf);
val inPath = new Path(srcPath);
val outPath = new Path(dstPath);
val key = new Text();
val value = new BytesWritable();
val in = fs.open(inPath);
val buffer = new Array[Byte](in.available())
in.read(buffer);
var writer = SequenceFile.createWriter(fs, conf, outPath, key.getClass(),value.getClass());
writer.append(new Text(inPath.getName()), new BytesWritable(buffer));
IOUtils.closeStream(writer);
}
catch {
case io: IOException => println(io.getMessage)
case illegalArgument: IllegalArgumentException => println(illegalArgument.getMessage)
}
}
}
示例3: Barcodes
//设置package包名称以及导入依赖的类
package controllers
import play.api.mvc.{Action, Controller}
class Barcodes extends Controller{
val ImageResolution = 144
def barcode(ean: Long) = Action{
import java.lang.IllegalArgumentException
val MimeType = "image/png"
try{
val imageData = ean13BarCode(ean, MimeType)
Ok(imageData).as(MimeType)
}catch{
case e:IllegalArgumentException =>
BadRequest("Couldn't generate bar code. Error: " + e.getMessage)
}
}
def ean13BarCode(ean:Long, mimeType: String) : Array[Byte] = {
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.upcean.EAN13Bean
val output: ByteArrayOutputStream = new ByteArrayOutputStream
val canvas: BitmapCanvasProvider =
new BitmapCanvasProvider(output, mimeType, ImageResolution,
BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barcode = new EAN13Bean()
barcode.generateBarcode(canvas, String valueOf ean)
canvas.finish
output.toByteArray
}
}
示例4: Barcodes
//设置package包名称以及导入依赖的类
package controllers
import play.api.mvc.{Action, Controller}
class Barcodes extends Controller {
val ImageResolution = 144
def barcode(ean: Long) = Action {
import java.lang.IllegalArgumentException
val MimeType = "image/png"
try {
val imageData = ean13BarCode(ean, MimeType)
Ok(imageData).as(MimeType)
}
catch {
case e: IllegalArgumentException =>
BadRequest("Couldn’t generate bar code. Error: " + e.getMessage)
}
}
def ean13BarCode(ean: Long, mimeType: String): Array[Byte] = {
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.upcean.EAN13Bean
val output: ByteArrayOutputStream = new ByteArrayOutputStream
val canvas: BitmapCanvasProvider =
new BitmapCanvasProvider(output, mimeType, ImageResolution,
BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barcode = new EAN13Bean()
barcode.generateBarcode(canvas, String valueOf ean)
canvas.finish
output.toByteArray
}
}
示例5: Barcodes
//设置package包名称以及导入依赖的类
package controllers
import play.api.mvc.{Action, Controller}
class Barcodes extends Controller {
val ImageResolution = 144
def barcode(ean: Long) = Action {
import java.lang.IllegalArgumentException
val MimeType = "image/png"
try {
val imageData = ean13BarCode(ean, MimeType)
Ok(imageData).as(MimeType)
}
catch {
case e: IllegalArgumentException =>
BadRequest("Couldn’t generate bar code. Error: " + e.getMessage)
}
}
def ean13BarCode(ean: Long, mimeType: String): Array[Byte] = {
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.upcean.EAN13Bean
val output: ByteArrayOutputStream = new ByteArrayOutputStream
val canvas: BitmapCanvasProvider =
new BitmapCanvasProvider(output, mimeType, ImageResolution,
BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barcode = new EAN13Bean()
barcode.generateBarcode(canvas, String valueOf ean)
canvas.finish
output.toByteArray
}
}
示例6: MinHashDocument
//设置package包名称以及导入依赖的类
package com.stevens.minhash
import java.nio.charset.StandardCharsets
import java.lang.IllegalArgumentException
import com.google.common.hash._
class MinHashDocument(text: String, signatureLength: Int = 100, shingleLength: Int = 5, seed: Int = 5) {
def generateShingles(): Iterator[String] = {
text.split("\\s+").sliding(shingleLength).map(gram => gram.mkString(" "))
}
def generateMinHashSignature(): Array[Int] = {
(seed to (seed + signatureLength - 1)).map { randomSeed =>
val hashFunction: HashFunction = Hashing.murmur3_32(randomSeed)
generateShingles().map(shingle => hashFunction.hashString(shingle, StandardCharsets.UTF_8).asInt).min
}.toArray
}
}
object MinHashDocument {
def jaccardSimilarity[A](item1: Iterable[A], item2: Iterable[A]): Double = {
val set1: Set[A] = item1.toSet
val set2: Set[A] = item2.toSet
set1.intersect(set2).size.toDouble / set1.union(set2).size.toDouble
}
def minhashSimilarity[A](item1: Array[A], item2: Array[A]): Double = {
if (item1.length != item2.length) {
throw new IllegalArgumentException("MinHashes must be equal length")
}
val agreeingRows = item1.zip(item2).map { case(val1, val2) =>
if (val1 == val2) {
1
} else {
0
}
}.sum
agreeingRows.toDouble / item1.length.toDouble
}
}
示例7: BarcodesController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import play.api._
import play.api.mvc._
class BarcodesController @Inject() extends Controller {
val ImageResolution = 144
def ean13BarCode(ean: Long, mimeType: String): Array[Byte] = {
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.upcean.EAN13Bean
val output: ByteArrayOutputStream = new ByteArrayOutputStream
val canvas: BitmapCanvasProvider = new BitmapCanvasProvider(output, mimeType, ImageResolution, BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barcode = new EAN13Bean()
barcode.generateBarcode(canvas, String valueOf ean)
canvas.finish
output.toByteArray
}
def barcode(ean: Long) = Action {
import java.lang.IllegalArgumentException
val MimeType = "image/png"
try {
val imageData = ean13BarCode(ean, MimeType)
Ok(imageData).as(MimeType)
} catch {
case e: IllegalArgumentException =>
BadRequest("Couldn’t generate bar code. Error: " + e.getMessage)
}
}
}
示例8: BarcodesController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.{Inject, Singleton}
import play.api.mvc.{Action, Controller}
@Singleton
class BarcodesController @Inject() extends Controller {
val ImageResolution = 144
def barcode(ean: Long) = Action {
import java.lang.IllegalArgumentException
val MimeType = "image/png"
try{
val imageData = ean13BarCode(ean, MimeType)
Ok(imageData).as(MimeType)
}catch {
case e: IllegalArgumentException =>
BadRequest("Couldn't generate bar code. Error: " + e.getMessage)
}
}
def ean13BarCode(ean: Long, mimeType: String) : Array[Byte] = {
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.upcean.EAN13Bean
var output: ByteArrayOutputStream = new ByteArrayOutputStream
var canvas: BitmapCanvasProvider =
new BitmapCanvasProvider(output, mimeType, ImageResolution,
BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barCode = new EAN13Bean()
barCode.generateBarcode(canvas, String valueOf ean)
canvas.finish
output.toByteArray
}
}
示例9: BarcodesController
//设置package包名称以及导入依赖的类
package controllers
import java.awt.image.BufferedImage
import javax.inject.{Inject, Singleton}
import play.api.Configuration
import play.api.mvc.{Action, Controller}
@Singleton
class BarcodesController @Inject() (val configuration: Configuration) extends Controller {
val ImageResolution = 144
def barcode(ean: Long) = Action {
import java.lang.IllegalArgumentException
val MimeType = "image/png"
try {
val imageData = ean13BarCode(ean, MimeType)
Ok(imageData).as(MimeType)
} catch {
case e: IllegalArgumentException =>
BadRequest("Couldn't generate bar code. Error: " + e.getMessage)
}
}
def ean13BarCode(ean: Long, mimeType: String): Array[Byte] = {
import java.io.ByteArrayOutputStream
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.upcean.EAN13Bean
val output: ByteArrayOutputStream = new ByteArrayOutputStream()
val canvas: BitmapCanvasProvider = new BitmapCanvasProvider(output, mimeType, ImageResolution,
BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barcode = new EAN13Bean()
barcode.generateBarcode(canvas, String valueOf ean)
canvas.finish()
output.toByteArray
}
}
示例10: Main
//设置package包名称以及导入依赖的类
package numb.app
import java.lang.IllegalArgumentException
import com.typesafe.config.{Config, ConfigFactory}
import numb.translate.NumberTranslationService
import scaldi.{Injectable, Injector, TypesafeConfigInjector}
object Main extends App with Injectable {
// Declare injector bindings where properties are added after module bindings
implicit val injector : Injector = TypesafeConfigInjector(ConfigFactory.load()) :: new NumbModule
val translator: NumberTranslationService = inject[NumberTranslationService]
if (args.length == 1) {
try {
println(translator.translate(args(0)))
} catch {
case e:IllegalArgumentException => println("Please enter a number only containing digits between 0 and 1000001")
}
} else {
println("Please pass exactly one argument only containing digits.")
}
}
示例11: BarcodesController
//设置package包名称以及导入依赖的类
package controllers
import play.api.mvc.Controller
import javax.inject.Inject
import javax.inject.Singleton
import play.api.mvc.Action
@Singleton
class BarcodesController @Inject() extends Controller {
val ImageResolution = 144
def barcode(ean: Long) = Action {
import java.lang.IllegalArgumentException
val MimeType = "image/png"
try {
val imageData = ean13BarCode(ean, MimeType)
Ok(imageData).as(MimeType)
} catch {
case e: IllegalArgumentException =>
BadRequest("Couldn’t generate bar code. Error: " + e.getMessage)
}
}
def ean13BarCode(ean: Long, mimeType: String): Array[Byte] = {
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider
import org.krysalis.barcode4j.impl.upcean.EAN13Bean
val output: ByteArrayOutputStream = new ByteArrayOutputStream
val canvas: BitmapCanvasProvider =
new BitmapCanvasProvider(output, mimeType, ImageResolution,
BufferedImage.TYPE_BYTE_BINARY, false, 0)
val barcode = new EAN13Bean()
barcode.generateBarcode(canvas, String valueOf ean)
canvas.finish
output.toByteArray
}
}