com.github.shyiko.mysql.binlog.event.deserialization.WriteRowsEventDataDeserializer Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2013 Stanley Shyiko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.shyiko.mysql.binlog.event.deserialization;
import com.github.shyiko.mysql.binlog.event.TableMapEventData;
import com.github.shyiko.mysql.binlog.event.WriteRowsEventData;
import com.github.shyiko.mysql.binlog.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.BitSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* @author Stanley Shyiko
*/
public class WriteRowsEventDataDeserializer extends AbstractRowsEventDataDeserializer {
private boolean mayContainExtraInformation;
public WriteRowsEventDataDeserializer(Map tableMapEventByTableId) {
super(tableMapEventByTableId);
}
public WriteRowsEventDataDeserializer setMayContainExtraInformation(boolean mayContainExtraInformation) {
this.mayContainExtraInformation = mayContainExtraInformation;
return this;
}
@Override
public WriteRowsEventData deserialize(ByteArrayInputStream inputStream) throws IOException {
WriteRowsEventData eventData = new WriteRowsEventData();
eventData.setTableId(inputStream.readLong(6));
inputStream.skip(2); // reserved
if (mayContainExtraInformation) {
int extraInfoLength = inputStream.readInteger(2);
inputStream.skip(extraInfoLength - 2);
}
int numberOfColumns = inputStream.readPackedInteger();
eventData.setIncludedColumns(inputStream.readBitSet(numberOfColumns, true));
eventData.setRows(deserializeRows(eventData.getTableId(), eventData.getIncludedColumns(), inputStream));
return eventData;
}
private List deserializeRows(long tableId, BitSet includedColumns, ByteArrayInputStream inputStream)
throws IOException {
List result = new LinkedList();
while (inputStream.available() > 0) {
result.add(deserializeRow(tableId, includedColumns, inputStream));
}
return result;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy