// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.olio.communication.filetransfer; import com.olio.communication.messages.files.ChunkRequest; import com.olio.communication.messages.files.FileChunk; import com.olio.data.object.transfer.FileTransfer; import com.olio.util.ALog; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public abstract class FileTransferer { private static final int CHUNK_SIZE = 5120; public FileTransferer() { } protected Integer chunkReceived(FileChunk filechunk) { Object obj; Object obj1; Object obj2; ALog.v((new StringBuilder()).append("Received another chunk for ").append(filechunk.getFileIdentifier()).append(" starting at: ").append(filechunk.getStartingByte()).toString(), new Object[0]); obj1 = null; obj2 = null; obj = obj1; FileOutputStream fileoutputstream = getFileOutputStreamForChunk(filechunk); obj = obj1; obj1 = new BufferedOutputStream(fileoutputstream); long l1; l1 = fileoutputstream.getChannel().size(); ALog.d("FileSize: %d Chunk startingByte: %d", new Object[] { Long.valueOf(l1), Integer.valueOf(filechunk.getStartingByte()) }); if (l1 == (long)filechunk.getStartingByte()) goto _L2; else goto _L1 _L1: ALog.v("This chunk does not start at the right point in the file", new Object[0]); int i = (int)l1; obj = Integer.valueOf(i); filechunk = ((FileChunk) (obj)); if (obj1 == null) { break MISSING_BLOCK_LABEL_147; } ((BufferedOutputStream) (obj1)).close(); filechunk = ((FileChunk) (obj)); _L6: return filechunk; _L2: if (filechunk.getBytes() != null) { ALog.v("writing chunk bytes to output stream", new Object[0]); ((BufferedOutputStream) (obj1)).write(filechunk.getBytes(), 0, filechunk.getBytes().length); } ALog.v("flushing output stream", new Object[0]); ((BufferedOutputStream) (obj1)).flush(); if (filechunk.getBytes() != null) goto _L4; else goto _L3 _L3: ALog.v("chunk byte array is null. FileSize: %d", new Object[] { Long.valueOf(l1) }); int j = (int)l1; obj = Integer.valueOf(j); filechunk = ((FileChunk) (obj)); if (obj1 == null) goto _L6; else goto _L5 _L5: ((BufferedOutputStream) (obj1)).close(); return ((Integer) (obj)); filechunk; _L12: ALog.e("IO Exception when writing file chunk", filechunk, new Object[0]); _L9: return null; _L4: int k; int l; ALog.v((new StringBuilder()).append("Requesting another chunk for: ").append(filechunk.getFileIdentifier()).toString(), new Object[0]); ALog.v("offset = %d", new Object[] { Integer.valueOf(filechunk.getStartingByte() + filechunk.getBytes().length) }); k = filechunk.getStartingByte(); l = filechunk.getBytes().length; obj = Integer.valueOf(k + l); filechunk = ((FileChunk) (obj)); if (obj1 == null) goto _L6; else goto _L7 _L7: ((BufferedOutputStream) (obj1)).close(); return ((Integer) (obj)); obj1; filechunk = obj2; _L11: obj = filechunk; ALog.e("Error opening file for writing", ((Throwable) (obj1)), new Object[0]); if (filechunk == null) goto _L9; else goto _L8 _L8: filechunk.close(); goto _L9 _L10: if (obj == null) { break MISSING_BLOCK_LABEL_375; } ((BufferedOutputStream) (obj)).close(); throw filechunk; filechunk; obj = obj1; goto _L10 FileNotFoundException filenotfoundexception; filenotfoundexception; filechunk = ((FileChunk) (obj1)); obj1 = filenotfoundexception; goto _L11 filechunk; goto _L12 filechunk; goto _L10 } protected abstract void fileTransferComplete(FileTransfer filetransfer); protected abstract FileInputStream getFileInputStreamForRequest(ChunkRequest chunkrequest) throws IOException; protected abstract FileOutputStream getFileOutputStreamForChunk(FileChunk filechunk) throws FileNotFoundException; protected abstract long getFileSize(ChunkRequest chunkrequest); protected abstract String getSender(); protected void sendChunkForRequest(ChunkRequest chunkrequest) { Object obj; Object obj2; FileChunk filechunk; filechunk = new FileChunk(); obj = null; obj2 = null; Object obj1 = new BufferedInputStream(getFileInputStreamForRequest(chunkrequest)); int i; i = (int)(getFileSize(chunkrequest) - (long)chunkrequest.getRequestedStartingByte()); ALog.v((new StringBuilder()).append("SEND CHUNK: Sending another chunk for: ").append(chunkrequest.getFileIdentifier()).append(" remaining bytes: ").append(i).toString(), new Object[0]); if (i <= 5120) goto _L2; else goto _L1 _L1: ALog.v("creating %d byte array", new Object[] { Integer.valueOf(5120) }); obj = new byte[5120]; _L10: ((BufferedInputStream) (obj1)).skip(chunkrequest.getRequestedStartingByte()); ((BufferedInputStream) (obj1)).read(((byte []) (obj)), 0, obj.length); if (i <= 5120) goto _L4; else goto _L3 _L3: ALog.v((new StringBuilder()).append("SEND CHUNK: Sending another chunk for: ").append(chunkrequest.getFileIdentifier()).append(" not finished ").toString(), new Object[0]); _L11: filechunk.setBytes(((byte []) (obj))); filechunk.setFileIdentifier(chunkrequest.getFileIdentifier()); filechunk.setStartingByte(chunkrequest.getRequestedStartingByte()); filechunk.setFileSource("Android"); if (obj1 == null) { break MISSING_BLOCK_LABEL_212; } ((BufferedInputStream) (obj1)).close(); _L9: if (filechunk.getFileIdentifier() != null) { sendFileChunk(filechunk); } _L8: return; _L2: if (i > 0) goto _L6; else goto _L5 _L5: ALog.v("sending final chunk", new Object[0]); filechunk.setFileIdentifier(chunkrequest.getFileIdentifier()); filechunk.setBytes(null); filechunk.setStartingByte(chunkrequest.getRequestedStartingByte()); filechunk.setFileSource("Android"); sendFileChunk(filechunk); if (obj1 == null) goto _L8; else goto _L7 _L7: try { ((BufferedInputStream) (obj1)).close(); return; } // Misplaced declaration of an exception variable catch (ChunkRequest chunkrequest) { } _L15: ALog.e("IO Exception when getting file chunk", chunkrequest, new Object[0]); goto _L9 _L6: ALog.v("creating %d byte array", new Object[] { Integer.valueOf(i) }); obj = new byte[i]; goto _L10 _L4: ALog.v((new StringBuilder()).append("SEND CHUNK: Sending another chunk for: ").append(chunkrequest.getFileIdentifier()).append(" last chunk ").toString(), new Object[0]); goto _L11 obj; chunkrequest = ((ChunkRequest) (obj1)); obj1 = obj; _L14: obj = chunkrequest; ALog.e("Error opening requested file", ((Throwable) (obj1)), new Object[0]); if (chunkrequest == null) goto _L9; else goto _L12 _L12: chunkrequest.close(); goto _L9 _L13: if (obj == null) { break MISSING_BLOCK_LABEL_399; } ((BufferedInputStream) (obj)).close(); throw chunkrequest; chunkrequest; obj = obj1; goto _L13 obj1; chunkrequest = obj2; goto _L14 chunkrequest; goto _L15 chunkrequest; goto _L13 } protected abstract void sendFileChunk(FileChunk filechunk); }