Feb. 3rd, 2012

java wtf

Feb. 3rd, 2012 11:09 am
juan_gandhi: (Default)
Ever tried new File(".").getParent()?

Returns null

as opposed to new File(new File(".").getAbsolutePath()).getParent()

How is it much better than Perl (which, by the way, will work properly in this case)?
juan_gandhi: (Default)
  val t: Thread = new Thread("Server at " + port) {

    val dispatch = Map("POST /status/success" -> processSuccess _,
                       "POST /status/failure" -> processFailure _,
                       "POST /queryrunstate"  -> processRunQuery _,
                       "GET /comet_request"   -> tellThemToShutUp _
    )
    
    override def run {
      while (!Thread.interrupted()) {
        try {
          val s = ss.accept
          val source = Source.fromInputStream(s.getInputStream)
          val rq = source.getLines.next
          try {
            val f = dispatch.keys.find(rq startsWith _).map(dispatch).getOrElse(ignore _)
            f(rq, s, source)
          } catch {
            case se : SocketException => log(se)
          } finally {
            s.close
          }
        } catch {
          case ioe: IOException => log(ioe)
          case ie: InterruptedException => return
        }
      }
    }
  }

  def tellThemToShutUp(rq: String,  socket: Socket, source: Source) {
    Response("oh shut up, this is not the web server you are lookign for", "410 Gone")
  }

juan_gandhi: (Default)
 
 val serverSocket = try {new ServerSocket(port)} catch {
    case e: java.net.BindException => {
      println("wtf, several copies? what is it? ")
      throw new IllegalStateException("this port, " + port + ", is already taken!")
    }
  }

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 16th, 2025 02:30 am
Powered by Dreamwidth Studios