次の Java コードを Objective C に移植しようとしています。
myByteBuffer = new ByteArrayOutputStream(myCfA.length() + 1);
myByteBuffer.write(myCfA.getBytes());
myByteBuffer.write(new byte[]{0});
myWriter.write(myByteBuffer.toByteArray());
myWriter.flush();
関連するObjective-Cコードです
NSInteger strLength = self.myCfA.length;
NSMutableString *response = [NSMutableString stringWithCapacity:strLength];
[response appendString:self.myCfA];
[response appendString:@"0"];
NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSUTF8StringEncoding]];
NSInteger bytesCount = [self.outputStream write:[data bytes] maxLength:[data length]];
NSMutableString を取得してから NSData に変換し、バイトを取得するという私のアプローチは正しいアプローチですか? また、new byte[]{0} については、0 を文字列として直接追加しています。私が間違っている場合は、私を修正してください。ここには、追跡できない問題があります。
ありがとう