"file" is a Mono object received from RestController, I want to convert it into byte[]
byte[] bytes=file.map(filePart -> filePart.content().map(dataBuffer -> dataBuffer.asByteBuffer().array()}));
it says no instance to variable R exist so that it conforms byte[]
for starters that } near the end makes this not compile!
But also, if file is a Mono, then map will also return a Mono, you will need to .block() to get out a value out.
and then you probably want to figure out how to get rid of that block again, if you really want to do reactive.
Related
I have a HashMap< String, List> which I fill inside the Java class. When I try to print it out in the Velocity template, it looks fine.
$!valuesMap ##gives {33=[texxxxt], 34=[2019-03-31], 35=[admin], 37=[P1], 40=[value1, value2]}
When I try to access the values directly, it also looks fine.
$!valuesMap.get("40") ##gives [value1, value2]
Problem arises when I try to use a dynamic variable to access the map. I have a list of objects over which I iterate, and each of these objects has an ID. However I cant figure out how to retrieve the value from the map using this ID.
#foreach( $field in $fields )
$!field.ID ##gives the id of the object, i.e. 40
##I would assume this would give me [value1, value2] when ID is 40, but it returns nothing
$!valuesMap.get($!field.ID)
#end
I have tried assigning the ID to a new variable (variable itself prints out fine, but again when I try to access the map, I get nothing). I have tried the notation suggested here and nothing ever prints out, it is honestly driving me up the wall, because I am probably missing something very simple, but cant figure out what it is.
Velocity Engine 1.7 does not convert method arguments towards expected types. So if $field.ID is a number, you have to enclose it in double quotes to get a string:
$valuesMap.get("$field.ID")
Otherwise, the engine simply doesn't find a proper method to call.
Starting with 2.0, Velocity Engine will automatically convert method arguments towards expected types, and your code will work as expected.
My constructor is as next
ScaperEngine::ScaperEngine(GrabberType grabberType, bool timing) {
switch (grabberType)
{
case GrabberType::DepthSenseGrabber:
this->interface = new pcl::DepthSenseGrabber("");
break;
default:
throw new std::exception("Grabber type wasn't chosen correctly");
break;
}
executionPipeline = new ExecutionPipeline();
executionPipeline->setTiming(timing);
}
And then I have some code like:
void ScaperEngine::StartPipeline()
{
IPCLNormalCalculator* normalCalculator = new PCLNormalCalculator(normalCalcMaxDepthChangeFactor, normalSmoothingSize);
executionPipeline->SetPCLNormalCalculator(normalCalculator);
The most strange thing is that the constructor is building executionPipeline in the right way putting its place in memory in 0x0000020ef385e830, but when my c# managed code calls StartPipeline the executionPipeline address changed to 0xcdcdcdcdcdcdcdcd and in Quick Watch the following text appears for its variables <Unable to read memory>.
Please anyone has a clue whats going on?
With many thanks.
The 0xcdcdcdcdcdcdcdcd you are seeing is a special feature of the Visual Studio debugger that represents uninitialized heap memory. A more comprehensive list of codes are available from this StackOverflow question. In brief, it seems as though your C# code is calling StartPipeline() on an invalid object. This could happen, for example, if the pointer is altered to point to a random location in heap memory. Make your C# code (and the runtime) is properly storing the pointer to the ScraperEngine object and not corrupting it along the way.
This is a follow-up on the question Why do I get a list of numbers instead of JSON when using the Twitch API via Rust? If I use the solution suggested in the previous post:
Use the response.get_body() method to get a list of byte number which can be converted to a Result with from_utf8() method.
This returns a Result with everything in it. I'm not sure how to manipulate it. I was hoping I could use it like an array but the docs and rustbyexample don't seem to explain it. What is the purpose of a Result type?
This is the exact response that I'm getting from the body after converting it to UTF-8.
The Result type does not help you here – it just stores arbitrary data and is used for error handling (instead of exceptions). But you can use the rustc_serialize crate to parse the string returned by the Result:
extern crate rustc_serialize;
use rustc_serialize::json::Json;
fn main() {
let response_result = /* ... */;
let data = response_result.unwrap();
let json = Json::from_str(&data).unwrap();
println!("{}", json.find("status").unwrap());
}
It seems I'm unable to use a method reference of an object in Kotlin. This feature exists in Java.
For example in Java if I was looping through a string to append each character to a writer:
string.forEach(writer::append);
But in Kotlin using the same syntax does not work because:
For now, Kotlin only supports references to top-level and local functions and members of classes, not individual instances. See the docs here.
So, you can say Writer::append and get a function Writer.(Char) -> Writer, but taking a writer instance and saying writer::append to get a function (Char) -> Writer is not supported at the moment.
Starting from Kotlin 1.1 writer::append is a perfectly valid bound callable reference.
However, you still cannot write string.forEach(writer::append) because Writer#append method returns a Writer instance and forEach expects a function that returns Unit.
I am using Kotlin 1.3 and while referencing a Java method I got a very similar error. As mentioned in this comment, making a lambda and passing it to the forEach method is a good option.
key.forEach { writter.append(it) }
Being it the implicit name of a single parameter.
I am writing an Eclipse plug-in that uses JDT AST's ASTParser to parse a method. I am looking within that method for the creation of a particular type of object.
When I find a ClassInstanceCreation, I call getType() on it to see what type is being instantiated. I want to be sure that the fully-resolved type being dealt with there is the one I think it is, so I tell the resultant Type object to resolveBinding(). I get null back even though there are no compilation errors and even though I called setResolveBindings(true) on my ASTParser. I gave my ASTParser (via setSource()) the ICompilationUnit that contains my method, so the parser has access to the entire workspace context.
final IMethod method = ...;
final ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setResolveBindings(true);
parser.setSource(method.getCompilationUnit());
parser.setSourceRange(method.getSourceRange().getOffset(), method.getSourceRange().getLength());
parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
final TypeDeclaration astRoot = (TypeDeclaration) parser.createAST(null);
final ClassInstanceCreation classInstanceCreation = walkAstAndFindMyExpression(astRoot);
final Type instantiatedType = classInstanceCreation.getType();
System.out.println("BINDING: " + instantiatedType.resolveBinding());
Why does resolveBinding() return null? How can I get the binding information?
Tucked away at the bottom of the overview of ASTParser.setKind(), carefully hidden from people troubleshooting resolveBinding() and setResolveBindings(), is the statement
Binding information is only computed when kind is K_COMPILATION_UNIT.
(from the online Javadoc)
I don't understand offhand why this would be the case, but it does seem to point pretty clearly at what needs to be different!