Record Class StaticFileResponse
java.lang.Object
java.lang.Record
net.jrodolfo.java_evolution.java18.simple_web_server.StaticFileResponse
- Record Components:
statusCode- the HTTP status codebody- the response body
Represents a response returned by the local static-file server example.
The Java 18 feature is about serving static files quickly. This record keeps the client-side verification small so tests can assert the HTTP status and response body without exposing learners to a full web framework.
-
Constructor Summary
ConstructorsConstructorDescriptionStaticFileResponse(int statusCode, String body) Creates an instance of aStaticFileResponserecord class. -
Method Summary
Modifier and TypeMethodDescriptionbody()Returns the value of thebodyrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanChecks whether the requested static file was not found.booleanChecks whether the server returned a successful HTTP response.intReturns the value of thestatusCoderecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
StaticFileResponse
Creates an instance of aStaticFileResponserecord class.- Parameters:
statusCode- the value for thestatusCoderecord componentbody- the value for thebodyrecord component
-
-
Method Details
-
isSuccessful
public boolean isSuccessful()Checks whether the server returned a successful HTTP response.- Returns:
truefor any 2xx status code
-
isNotFound
public boolean isNotFound()Checks whether the requested static file was not found.- Returns:
truewhen the status code is 404
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
statusCode
public int statusCode()Returns the value of thestatusCoderecord component.- Returns:
- the value of the
statusCoderecord component
-
body
-