001/**************************************************************** 002 * Licensed to the Apache Software Foundation (ASF) under one * 003 * or more contributor license agreements. See the NOTICE file * 004 * distributed with this work for additional information * 005 * regarding copyright ownership. The ASF licenses this file * 006 * to you under the Apache License, Version 2.0 (the * 007 * "License"); you may not use this file except in compliance * 008 * with the License. You may obtain a copy of the License at * 009 * * 010 * http://www.apache.org/licenses/LICENSE-2.0 * 011 * * 012 * Unless required by applicable law or agreed to in writing, * 013 * software distributed under the License is distributed on an * 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 015 * KIND, either express or implied. See the License for the * 016 * specific language governing permissions and limitations * 017 * under the License. * 018 ****************************************************************/ 019 020package org.apache.james.mime4j.stream; 021 022 023import java.io.InputStream; 024 025/** 026 * Raw MIME entity. Such entities will not be parsed into elements 027 * by the parser. They are meant to be consumed as a raw data stream 028 * by the caller. 029 */ 030public class RawEntity implements EntityStateMachine { 031 032 private final InputStream stream; 033 034 private EntityState state; 035 036 RawEntity(InputStream stream) { 037 this.stream = stream; 038 this.state = EntityState.T_RAW_ENTITY; 039 } 040 041 public EntityState getState() { 042 return state; 043 } 044 045 /** 046 * This method has no effect. 047 */ 048 public void setRecursionMode(RecursionMode recursionMode) { 049 } 050 051 public EntityStateMachine advance() { 052 state = EntityState.T_END_OF_STREAM; 053 return null; 054 } 055 056 /** 057 * Returns raw data stream. 058 */ 059 public InputStream getContentStream() { 060 return stream; 061 } 062 063 /** 064 * This method has no effect and always returns <code>null</code>. 065 */ 066 public BodyDescriptor getBodyDescriptor() { 067 return null; 068 } 069 070 /** 071 * This method has no effect and always returns <code>null</code>. 072 */ 073 public RawField getField() { 074 return null; 075 } 076 077 /** 078 * This method has no effect and always returns <code>null</code>. 079 */ 080 public String getFieldName() { 081 return null; 082 } 083 084 /** 085 * This method has no effect and always returns <code>null</code>. 086 */ 087 public String getFieldValue() { 088 return null; 089 } 090 091 /** 092 * @see org.apache.james.mime4j.stream.EntityStateMachine#getDecodedContentStream() 093 */ 094 public InputStream getDecodedContentStream() throws IllegalStateException { 095 throw new IllegalStateException("Raw entity does not support stream decoding"); 096 } 097 098}